Emit __all__ in shared-split _generated.py package files - #128
Merged
Conversation
The shared-module-split layout writes each subpackage's _generated.py with an explicit `from <package>.<ext> import (...)` list re-exported by the sibling __init__'s `from ._generated import *`. Without an __all__, static analysis flagged the imported names as unused and the wildcard re-export as namespace-polluting. Emit a sorted __all__ of the re-exported names (imported extension names plus the TemplateClass stub base names), mirroring the top-level flatten file which already did this. The TemplateClass helper is no longer leaked. The module-per-subpackage layout re-exports a whole extension via `import *`, whose names are not all known here, so it emits no __all__ (unchanged). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #128 +/- ##
========================================
Coverage 99.68% 99.68%
========================================
Files 31 31
Lines 2536 2563 +27
Branches 545 551 +6
========================================
+ Hits 2528 2555 +27
Misses 7 7
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Switch the module-per-subpackage _generated.py from `from .<module> import *` to an explicit name list, matching the shared-module split. This makes the emitted __all__ exact for both layouts (so `from ._generated import *` in the hand-written __init__.py is non-polluting and never leaks TemplateClass or silently re-exports a hand-written extension binding), and lets the layout's `exclude` list be honored here too: an excluded class/enum/free function is held out of the imports and __all__ while staying registered in the extension. Demonstrate exclude in the shapes example by hiding the abstract AbstractShape/ AbstractPolygon bases while their concrete subclass RegularPolygon stays exposed and still inherits their bindings. Update the package-layer docs accordingly. Regenerated the shapes/cells _generated.py; genpackage unit tests at 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Both generators (module-per-subpackage and shared-module split) always pass an exact export_names now, so the optional `= None` default and the "emit no __all__" branch were production-dead — kept alive only by the render tests. Drop the default (moving export_names ahead of the two defaulted params) and always emit __all__; an empty module emits `__all__ = []`. Generated output is unchanged (shapes/cells regenerate byte-identical). Drop the now-obsolete omits-all test; genpackage unit tests stay at 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Generates explicit package exports to prevent namespace pollution and configuration drift, following issue #102.
Changes:
- Adds explicit extension imports and sorted
__all__declarations. - Supports
excludein module-per-subpackage layouts. - Updates examples, documentation, and tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
cppwg/genpackage.py |
Generates explicit imports, exports, and exclusions. |
tests/test_genpackage.py |
Tests imports, __all__, exclusions, and empty modules. |
doc/python-packages.md |
Documents explicit exports and exclude. |
examples/shapes/wrapper/package_layout.yaml |
Excludes abstract shape bases. |
examples/shapes/src/py/tests/test_classes.py |
Verifies excluded bases and inherited behavior. |
examples/shapes/src/py/pyshapes/primitives/_generated.py |
Curates primitive exports. |
examples/shapes/src/py/pyshapes/math_funcs/_generated.py |
Curates function exports. |
examples/shapes/src/py/pyshapes/geometry/_generated.py |
Curates geometry exports. |
examples/shapes/src/py/pyshapes/composites/_generated.py |
Curates composite exports. |
examples/cells/src/py/pycells/_generated.py |
Curates cell package exports. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #102