Skip to content

Declare the public top-level API in __all__ so type checkers export it - #1485

Closed
1915rising wants to merge 1 commit into
mozman:masterfrom
1915rising:fix/1484-public-api-exports
Closed

1915rising wants to merge 1 commit into
mozman:masterfrom
1915rising:fix/1484-public-api-exports

Conversation

@1915rising

Copy link
Copy Markdown
Contributor

Fixes #1484.

Because ezdxf ships a py.typed marker, pyright/Pylance follow the typing spec rule that a name imported into a package init is private unless it is listed in all or re-exported with a redundant alias. None of the top-level names were declared, so the README example itself failed checking: "new" is not exported from module "ezdxf" (reportPrivateImportUsage) — and the same applied to readfile, read, options, version, the DXF exception classes, the DXF version constants and every other re-export.

Reproduction (pyright, reportPrivateImportUsage=true, against a 6-line script using ezdxf.new, ezdxf.readfile, ezdxf.options, ezdxf.version, ezdxf.DXFError, ezdxf.InsertUnits): 6 reportPrivateImportUsage errors before, 0 after. The code always ran correctly; this is a declaration-only change, no runtime behaviour changes (star-import and ezdxf.new() verified unchanged).

Fix: add an explicit all to ezdxf/init.py listing all 53 public names — every name the module imports for re-export plus its public module-level constants and print_config.

Tests: new tests/test_10_issues/test_issue_1484_public_api_exports.py (3 tests) asserts every name in all exists, that every module-level from-import in init.py is exported (guards future re-exports), and that the documented names from the issue are exported. The new tests fail on the unmodified init (3 failed) and pass with the fix. tests/test_10_issues: 31 passed after. Broader spot check (test_533_shapefiles + test_00_dxf_low_level_structs): 576 passed.

@mozman

mozman commented Nov 22, 2026

Copy link
Copy Markdown
Owner

mypy works fine ...

@mozman mozman closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pylance shows an error for ezdxf.new()

2 participants