Minimize module-level imports for __init__.py
files
#16985
Labels
developer experience
Anything that improves the experience for Warehouse devs
needs discussion
a product management/policy issue maintainers and users should discuss
testing
Test infrastructure and individual tests
Over time, modules were converted to packages by renaming a file like
foo.py
tofoo/__init__.py
thus preservingimport foo
kind of statements.While generally fine, this has some odd implications on partial imports during traversals (I'll admit, I'm a little hazy on the specifics of how that happens).
During
pytest
runs, this often manifests as a circular import error from a partially imported module, leading to solutions like #13737An audit of "
__init__.py
files with more than 11 LOC (the size of our license header)" has 36 hits:Instead of trying to tackle all of that, look only at the ones that have another subdirectory (package) alongside the
__init__.py
file, since the issue seems to be with depth traversal.10 hits:
Moving most of the non-
includeme()
and__all__
code out of__init__.py
files should be relatively straightforward, and will keep import traversals "clean" of unintended side effects or partial initializations.The text was updated successfully, but these errors were encountered: