gh-127036: Update importlib.util._LazyModule.__getattribute__ to special-case requests for __spec__#127038
Conversation
Allow `importlib.util._LazyModule` to special-case its `__spec__` attribute so that the regular import machinery requesting that attribute doesn't trigger the full module load.
|
A few things I'm unsure of:
|
I think so since it changes the semantics and someone may have been relying on it.
I think what you already have in the PR suffices as it verifies things are working. |
|
And apologies for taking so long to get to this PR! |
|
FYI my approval is still gated on a news entry thanks to CI checking for it. |
|
Cheers! Looking at this with fresh eyes, the semantic change definitely warrants more than just a code change. In addition to the news entry, I'll attempt to tweak the |
importlib.util._LazyModule.__getattribute__ to special-case requests for __spec__.importlib.util._LazyModule.__getattribute__ to special-case requests for __spec__
Sounds great! |
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
@Sachaa-Thanasius do you think you want to continue to work on this and address the review comments? |
|
@Sachaa-Thanasius if you end up wanting to pick up this PR later just let me know, but otherwise I'm closing this PR due to lack of activity. |
|
Apologies, life was distracting. Still is. Also, I had second thoughts on the scope of this (e.g. maybe we actually want to return a copy of the spec, since it's mutable; maybe there are other import-related attributes we want to exclude like I'll come back to this when I'm in a better headspace (or maybe someone will beat me to it :D). |
Allow
importlib.util._LazyModuleto special-case its__spec__attribute so that when the regular import machinery requests that attribute, it doesn't trigger the full module load. This will make it easier to useimportlib.util.LazyLoader.