-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-45272: os.path should not be a frozen module #29329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Filipe Laíns <[email protected]>
# bpo-45272: os.path is not a concrete module, but an importable | ||
# attribute of 'os'. _imp.is_frozen('os.path') returns | ||
# False but it is frozen, so we check the loader here. | ||
fullname in sys.modules | ||
and sys.modules[fullname].__spec__.loader is FrozenImporter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericsnowcurrently, couldn't we do loader.origin == 'frozen'
instead? Are we planing to change the value of origin to the actual file or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related bpo: https://bugs.python.org/issue35321
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't we do loader.origin == 'frozen' instead?
Let's be explicit about it with the check you have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the reasoning is there some different frozen importer type might be added, and this code might break. That scenario seemed reasonable to me with the complex bootstrapping architecture, but, of course, I lack the experience to make educated guesses 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some different frozen importer type might be added, and this code might break.
We can deal with it if that ever happens. The set of conditions here is so specific, yet highly unlikely. Plus, if the check here somehow breaks in the future, the problem should be fairly obvious. However, I expect it wouldn't ever be a problem.
(Regardless, the point is moot now as I'm pretty sure we can drop the importlib change.)
This PR is stale because it has been open for 30 days with no activity. |
FYI, I'm trying to track down why I'd frozen os.path in the first place. It doesn't seem like it should be necessary. I remember it was in response to a failing test and it related to using the finder of the parent module and maybe something about runpy. I'm running the test suite with os.path not frozen to see. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(with the importlib changes dropped)
@@ -263,7 +263,13 @@ def _requires_builtin_wrapper(self, fullname): | |||
def _requires_frozen(fxn): | |||
"""Decorator to verify the named module is frozen.""" | |||
def _requires_frozen_wrapper(self, fullname): | |||
if not _imp.is_frozen(fullname): | |||
if not _imp.is_frozen(fullname) or ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that _imp.is_frozen()
treats any error (including FROZEN_EXCLUDED
) as "not frozen", which could lead to weirdness in some corner cases (e.g. _imp.is_frozen()
returns True but FrozenImporter.find_spec()
returns None).
That's not relevant for this PR, and probably not something to worry about all that much, but I hadn't noticed it before. 🙂
if not _imp.is_frozen(fullname) or ( | ||
# bpo-45272: os.path is not a concrete module, but an importable | ||
# attribute of 'os'. _imp.is_frozen('os.path') returns | ||
# False but it is frozen, so we check the loader here. | ||
fullname in sys.modules | ||
and sys.modules[fullname].__spec__.loader is FrozenImporter | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm pretty sure we don't need to add the special case here any more. I don't remember why I had to freeze os.path in the first place, other than that a test was failing. It must have been something that was fixed elsewhere, since the test suite passes now. So go ahead and drop this change.
if not _imp.is_frozen(fullname) or ( | |
# bpo-45272: os.path is not a concrete module, but an importable | |
# attribute of 'os'. _imp.is_frozen('os.path') returns | |
# False but it is frozen, so we check the loader here. | |
fullname in sys.modules | |
and sys.modules[fullname].__spec__.loader is FrozenImporter | |
): | |
if not _imp.is_frozen(fullname): |
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 |
Closing this in favor of a new PR to avoid either overwriting the commit history or using merge commit and pinging everyone. |
Signed-off-by: Filipe Laíns [email protected]
https://bugs.python.org/issue45272