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-123135: add support for path-like objects infnmatch.filter on POSIX platforms#123122

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

Conversation

@picnixz
Copy link
Member

@picnixzpicnixz commentedAug 18, 2024
edited
Loading

This fixes an inconsistency in thefnmatch module where path-like objects are allowed on Windows but not on POSIX platforms.

cc@barneygale since you were recently interested infnmatch!

@barneygale
Copy link
Contributor

Users might already expect thatfilter() accepts path-likenames, because its docs say:

It is the same as[n for n in names if fnmatch(n, pat)], but implemented more efficiently.

And thefnmatch() docs say:

Both parameters are case-normalized usingos.path.normcase()

And thenormcase() docs say:

Accepts apath-like object.

So I think we should fix the discrepancy and explicitly support path-likenames.

@picnixz
Copy link
MemberAuthor

Let's fix it then. I think I'll make it a bugfix rather than a feature.

@picnixzpicnixz changed the titleAdd tests for platform dependentfnmatch.filter behavioursgh-123135: fix path-like objects support infnmatch.filterAug 19, 2024
@picnixzpicnixz added stdlibStandard Library Python modules in the Lib/ directory and removed skip issue skip news testsTests in the Lib/test dir labelsAug 19, 2024
picnixz added a commit to picnixz/cpython that referenced this pull requestAug 19, 2024
Copy link
Contributor

@barneygalebarneygale left a comment

Choose a reason for hiding this comment

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

Looking good. It's worth a.. versionchanged:: directive in the docs to point out that path-like support was added in 3.14, and that in previous versions it only worked on Windows.

@bedevere-app
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 phraseI 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.

@picnixz
Copy link
MemberAuthor

picnixz commentedAug 21, 2024
edited
Loading

I have made the requested changes; please review again. By the way, I'm wondering whether we should explicitly callos.fspath infnmatchcase actually so that all functions have path-like support:

 def fnmatchcase(name, pat):     """Test whether FILENAME matches PATTERN, including case.      This is a version of fnmatch() which doesn't case-normalize     its arguments.     """     match = _compile_pattern(pat)-    return match(name) is not None+    return match(os.fspath(name)) is not None

@bedevere-app
Copy link

Thanks for making the requested changes!

@barneygale: please review the changes made to this pull request.

@picnixzpicnixz changed the titlegh-123135: fix path-like objects support infnmatch.filtergh-123135: add support for path-like objects infnmatch.filter on POSIX platformsAug 21, 2024
@@ -0,0 +1,3 @@
Added support for supplying:term:`path-like objects <path-like object>`
to the *names* parameter of:func:`fnmatch.filter`. Previously, such
objects were only accepted on non-POSIX platforms. Patch by Bénédikt Tran.
Copy link
Contributor

Choose a reason for hiding this comment

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

The only non-POSIX platform that we support is Windows:

Suggested change
objects were only accepted onnon-POSIX platforms. Patch by Bénédikt Tran.
objects were only accepted onWindows. Patch by Bénédikt Tran.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

What about WASI?

@barneygale
Copy link
Contributor

By the way, I'm wondering whether we should explicitly callos.fspath infnmatchcase actually so that all functions have path-like support

That sounds reasonable to me!

@picnixz
Copy link
MemberAuthor

See#123215 (comment) for the rationale of marking it as DO-NOT-MERGE for now.

@picnixz
Copy link
MemberAuthor

See#123215 (comment) for the rationale of closing this PR.

@picnixzpicnixz deleted the fnmatch-test-normcase-for-posix-vs-windows branchAugust 26, 2024 16:01
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@barneygalebarneygaleAwaiting requested review from barneygale

Assignees

No one assigned

Labels

awaiting change reviewDO-NOT-MERGEstdlibStandard Library Python modules in the Lib/ directory

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@picnixz@barneygale

[8]ページ先頭

©2009-2025 Movatter.jp