Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

FFY00
Copy link
Member

@FFY00 FFY00 commented Oct 30, 2021

Comment on lines +267 to +271
# 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
Copy link
Member Author

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Member Author

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 😛

Copy link
Member

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.)

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Nov 30, 2021
@ericsnowcurrently
Copy link
Member

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.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a 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 (
Copy link
Member

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. 🙂

Comment on lines +266 to +272
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
):
Copy link
Member

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.

Suggested 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):

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ericsnowcurrently ericsnowcurrently removed the stale Stale PR or inactive for long period of time. label Jan 12, 2022
@FFY00
Copy link
Member Author

FFY00 commented Nov 17, 2024

Closing this in favor of a new PR to avoid either overwriting the commit history or using merge commit and pinging everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants