-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 ( | ||||||||||||||||||
# 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 | ||||||||||||||||||
Comment on lines
+267
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ericsnowcurrently, couldn't we do There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Let's be explicit about it with the check you have. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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.) |
||||||||||||||||||
): | ||||||||||||||||||
Comment on lines
+266
to
+272
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Suggested change
|
||||||||||||||||||
raise ImportError('{!r} is not a frozen module'.format(fullname), | ||||||||||||||||||
name=fullname) | ||||||||||||||||||
return fxn(self, fullname) | ||||||||||||||||||
|
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 (includingFROZEN_EXCLUDED
) as "not frozen", which could lead to weirdness in some corner cases (e.g._imp.is_frozen()
returns True butFrozenImporter.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. 🙂