-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Should we test -X lazy_imports=all more? #149640
Copy link
Copy link
Open
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixestestsTests in the Lib/test dirTests in the Lib/test dirtopic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Metadata
Metadata
Assignees
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixestestsTests in the Lib/test dirTests in the Lib/test dirtopic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
Inspired by #149321 I decided to see how well the test suite works with
PYTHON_LAZY_IMPORTS=all/-X lazy_imports=all, which makes all imports lazy. It's nowhere near as bad as thenoneoption that we're considering removing, but a few parts of the stdlib are broken, and it seems worth considering if we want to fix these.Concrete issues I noticed:
__getattr__when reifying #144957 breaks test_typingtest_unittestfails becauseunittest.mainbecomes a module instead of a function.test_structis broken because of a test that doesexec("import struct")in a function; lazy imports are disallowed within functions. Similar issues affecttest_enum,test_traceback, andtest_future.test_symtableis broken because it fills its_flagslist by iterating overglobals(), which means it starts containing lazy import marker objects. Similarlytest_inspectbreaks because it iterates overvars()of a module.A few tests fail for legitimate reasons;
test_compilealltests that an import triggers pyc compilation;test_builtinasserts that__import__is used when in fact__lazy_import__gets used.Full list of failed modules on my machine:
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS