Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
bpo-41530: Handle unhandled IsADirectoryError and PermissionError in zoneinfo.ZoneInfo#21839
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Additionally handles `IsADirectoryError`, `PermissionError`, and `ValueError` raised when accessing specific resource names.
the-knights-who-say-ni commentedAug 12, 2020
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed thePSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find abugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please followthe steps outlined in the CPython devguide to rectify this issue. You cancheck yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
ValueError is documented as an exception raised elsewhere and as such need not be handled.
Why did you close your PR? |
bijij commentedAug 12, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm aware of this ignoring the Unsure as to what would be a good plan of attack to solve that issue. one crude solution could be to assume only TZif files lack extensions however there's obviously large room for future issues derived from that soltution. |
Uh oh!
There was an error while loading.Please reload this page.
Lib/zoneinfo/_common.py Outdated
| importimportlib.util | ||
| package_spec=importlib.util.find_spec(package_name) | ||
| resource_path=os.path.join(os.path.dirname(package_spec.origin),key) |
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.
imports+two lines of code is a risk of raising a new exception. You may do that before and use the path to load the resource. I'm not sure.
Is it possible that tzdata is in a ZIP file, or in memory but not on disk?
Maybe it's overcomplicated and maybe it's better to convertany OSError into a ZoneInfoNotFoundError. I let@pganssle decides what is the best.
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.
Yeah, I don't like this at all. Inimportlib_resources there's a way to determine if something is a directory or not using theimportlib.resources.files API.
That will complicate things a bit for the backport, though, which doesn't currently requireimportlib_resources in Python 3.8.
I'm inclined to go the simple way and catchallOSErrors instead of the more narrowly scoped ones. I realize this may frustrate some people debugging in unusual environments by disguising the source of some errors, but I don't love that the standardZoneInfo constructor is exposing details about the specifics of the underlying file system.
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.
@jaraco Do you know if there's an equivalent ofimportlib.resources.files('my.package').joinpath('resource').isdir() that works for Python 3.8's version ofimportlib.resources?
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.
In Python 3.8 and earlier,importlib.resources didn't support directories as resources - all resources were required to be files directly in a package.
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.
@jaraco Well, we're not really concerned with using a directory as a resource, the problem is that it appears thatimportlib.resources raisesPermissionError on Windows when a directory is specified, and we're trying to distinguish between the case where a purported resourceexists but is a directory and the case of a legitimate permissions error.
Is there no way to do that in the Python 3.8importlib.resources?
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.
swapped to usingimportlib.resources.files to locate the resource however inclined to agree that catching all OSError derivatives might prove less problematic.
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.
@pganssle Apologies for having dropped the ball on this one.
I don't believe there's a reliable in the older importlib.resources API to detect that a directory is present. It was meant to be the case that a directory was indistinguishable from 'not a resource'.
What I would recommend though is to useimportlib.resources here, but in the zoneinfo backport, useimportlib_resources, which implements thefiles() API even on Python 2.
Other OSError derivatives should be ignored.
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'm still not convinced about whether this is the right solution, but regardless of how we solve the issue, it does need tests.
Again I do think it would be better in some ways to start this as a PR againstbackports.zoneinfo to take advantage of the improved CI setup there, then migrate the code into CPython wholesale, but if you don't want to do that I will just make sure to backport the code before this is merged.
bedevere-bot commentedAug 14, 2020
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 |
Happy to start a PR against backports, won't be able to for about 10 hours or so though. |
I have made the requested changes; please review again |
bedevere-bot commentedSep 3, 2020
Thanks for making the requested changes! @pganssle: please review the changes made to this pull request. |
Uh oh!
There was an error while loading.Please reload this page.
Handles
IsADirectoryErrorandPermissionErrorraised when accessing specific resource names.https://bugs.python.org/issue41530