Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-138432: zoneinfo: improve error message for PathLike relative paths#138433

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

Merged
serhiy-storchaka merged 8 commits intopython:mainfromtungol:zoneinfo
Sep 11, 2025

Conversation

@tungol
Copy link
Contributor

@tungoltungol commentedSep 3, 2025
edited by bedevere-appbot
Loading

This corrects a small inconsistency with the error handling ofzoneinfo.reset_tzpath. A sequence ofos.PathLike instances is documented as valid input, but the error pathway for relative paths doesn't handle these correctly. This pull request corrects this, and adds a relevant test case.

Copy link
Member

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

Please add a news entry.

tungol reacted with thumbs up emoji
@tungol
Copy link
ContributorAuthor

Done.

@serhiy-storchaka
Copy link
Member

I suggest to callos.fspath() for all items before assigning them to TZPATH (and before checking that they are absolute paths). We can also add a check that they all are now strings (bytes object will cause error later infind_tzfile() andavailable_timezones()).

@tungol
Copy link
ContributorAuthor

tungol commentedSep 5, 2025
edited
Loading

I suggest to call os.fspath() for all items before assigning them to TZPATH (and before checking that they are absolute paths).

We can do that, but I don't think it's really necessary. Checking for absolute status is done withos.path.isabs, which already handles os.PathLike objects correctly. Within our code, TZPATH is consumed byfind_tzfile, which usesos.path.join to produce a string, so it's again automatically handled.

I found this issue while working on a program to apply typeshed stubs to the stdlib and then analyze with mypy, so I'm relatively confident that this is the only place in (python-source) stdlib where os.Pathlike values for TZPATH were overlooked. (Typeshed correctly annotates TZPATH astuple[str | PathLike[str], ...])

This leaves the possibility of third-party consumers of TZPATH being surprised by encountering anos.PathLike object instead of a string. If we want to change TZPATH to be restricted tostr only on that basis, that's probably reasonable, but I think that's probably best left for a different MR.

@serhiy-storchaka
Copy link
Member

It will help to check that if it is a path-like object, it isPathLike[str], notPathLike[Any].bytes andPathLike[bytes] in TZPATH will cause runtime error inos.path.join().

Anyway, if os.fspath() is already implicitly called inos.path.isabs() andos.path.join(), why not call it explicitly and save the result?

@tungol
Copy link
ContributorAuthor

@serhiy-storchaka Is this about what you were thinking?

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Thank you for your response@tungol. Yes, this is what I suggested.

Few more nitpicks.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

Thank you for your contribution.

tungol reacted with hooray emoji
@serhiy-storchakaserhiy-storchaka merged commit859aecc intopython:mainSep 11, 2025
49 checks passed
@serhiy-storchakaserhiy-storchaka added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsSep 11, 2025
@miss-islington-app
Copy link

Thanks@tungol for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks@tungol for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry,@tungol and@serhiy-storchaka, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 859aecc33b82f45e5b7ae30138d28f2a2f33a575 3.13

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestSep 11, 2025
…ath() (pythonGH-138433)* Improve error messages for path-like relative paths and path-like bytes paths.* TZPATH is now always a tuple of strings.(cherry picked from commit859aecc)Co-authored-by: Stephen Morton <git@tungol.org>
@bedevere-app
Copy link

GH-138777 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelSep 11, 2025
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull requestSep 11, 2025
…set_tzpath() (pythonGH-138433)* Improve error messages for path-like relative paths and path-like bytes paths.* TZPATH is now always a tuple of strings.(cherry picked from commit859aecc)Co-authored-by: Stephen Morton <git@tungol.org>
@bedevere-app
Copy link

GH-138778 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelSep 11, 2025
@tungoltungol deleted the zoneinfo branchSeptember 11, 2025 07:17
serhiy-storchaka added a commit that referenced this pull requestSep 11, 2025
…path() (GH-138433) (GH-138778)* Improve error messages for path-like relative paths and path-like bytes paths.* TZPATH is now always a tuple of strings.(cherry picked from commit859aecc)Co-authored-by: Stephen Morton <git@tungol.org>
encukou pushed a commit that referenced this pull requestOct 7, 2025
…path() (GH-138433) (GH-138777)* Improve error messages for path-like relative paths and path-like bytes paths.* TZPATH is now always a tuple of strings.(cherry picked from commit859aecc)Co-authored-by: Stephen Morton <git@tungol.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

+1 more reviewer

@uranusjruranusjruranusjr left review comments

Reviewers whose approvals may not affect merge requirements

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@tungol@serhiy-storchaka@uranusjr@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp