You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 the none option 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.
test_unittest fails because unittest.main becomes a module instead of a function.
test_struct is broken because of a test that does exec("import struct") in a function; lazy imports are disallowed within functions. Similar issues affect test_enum, test_traceback, and test_future.
test_symtable is broken because it fills its _flags list by iterating over globals(), which means it starts containing lazy import marker objects. Similarly test_inspect breaks because it iterates over vars() of a module.
A few tests fail for legitimate reasons; test_compileall tests that an import triggers pyc compilation; test_builtin asserts that __import__ is used when in fact __lazy_import__ gets used.
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
Linked PRs
lazy_imports=allagainst test suite #151090