I don’t know how to square this with what the PEP says:
If the global lazy imports flag is set to
"disabled"
, no potentially lazy import is ever imported lazily, the import filter is never called, and the behavior is equivalent to a regularimport
statement: the import is eager (as if the lazy keyword was not used).
If you follow the comments and replies back up you can see that the discussion about -X lazy_imports="disabled"
starts from whether it would be necessary to allow a filter in this case.
This is not a hypothetical issue and will definitely arise in reality. People already do things like setting TYPE_CHECKING = True
at runtime and it is already known that it breaks things. In the future such imports can be changed to use lazy import
but then -X lazy_imports="disabled"
becomes the new version of someone setting TYPE_CHECKING=True
at runtime. There needs to be a clear understanding of what the expectations are here:
Is it reasonable for a user of a library to expect that the library functions under -X lazy_imports="disabled"
?
If any one library in use in a given process does not support this then the whole process breaks entirely and immediately and there is no filter mechanism that can be used to make it work. I think that this is going to result in pressure on libraries to make this work but making it work removes a significant chunk of the benefit of using lazy imports since every use of lazy imports must be something that would have worked as an eager import.