GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-160900: support path-like objects in fnmatch filters by MonikaDvorackova · Pull Request #160980 · python/cpython

Conversation

@MonikaDvorackova

@MonikaDvorackova MonikaDvorackova commented Oct 30, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #160900.

Ensure fnmatch.filter() and fnmatch.filterfalse() normalize every name with os.path.normcase(), including on POSIX. This lets path-like objects such as pathlib.Path work consistently across platforms. Add regression tests for both functions.

  • Issue: fnmatch.filter and filterfalse work with pathlikes only on non-Posix platforms #160900

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@MonikaDvorackova
pythongh-160900: support path-like objects in fnmatch filters
0478814
@python-cla-bot

python-cla-bot Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Oct 30, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 30, 2026
fnmatch.filter and filterfalse work with pathlikes only on non-Posix platforms #160900
Open
@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
pythongh-160900: add NEWS entry
feb3718
@picnixz
picnixz self-requested a review November 4, 2026 13:30
picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Lib/test/test_fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Lib/fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-10-30-19-04-37.gh-issue-160900.007288.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
pythongh-160980: Document path-like filtering and optimize filterfalse
ed77e0a
@MonikaDvorackova

MonikaDvorackova commented Nov 4, 2026

Copy link
Copy Markdown
Author

@picnixz

Thank you for the review. I've addressed the requested changes:

  • Moved the path-like tests immediately after their corresponding filter and filterfalse tests.
  • Updated the documentation to describe path-like input support and preservation of the original objects.
  • Benchmarked the existing itertools.filterfalse implementation against a list comprehension and an explicit loop using pyperf, with input sizes of 10, 100, 1,000, and 10,000 elements.

The list comprehension was consistently the fastest, reducing execution time by approximately 18–21% compared with the previous implementation.

I've updated filterfalse() accordingly and removed the unused itertools import.

All 26 test_fnmatch tests pass, and git diff --check reports no issues.

The benchmark results are preliminary measurements from a CPython 3.16 debug build using pyperf --fast, rather than release-build performance figures.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
Merge branch 'main' into fix/fnmatch-filter-pathlike
c2f1cb1
@read-the-docs-community

read-the-docs-community Bot commented Nov 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35785545 | 📁 Comparing 584ec30 against main (44579b0)

  🔍 Preview build  

81 files changed · ± 81 modified

± Modified

  • builtins/functions.html
  • builtins/stdtypes.html
  • builtins/threadsafety.html
  • c-api/code.html
  • c-api/frame.html
  • c-api/gcsupport.html
  • c-api/gen.html
  • c-api/init_config.html
  • c-api/module.html
  • c-api/object.html
  • and 71 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 4, 2026

Copy link
Copy Markdown
Member

The benchmark results are preliminary measurements from a CPython 3.16 debug build using pyperf --fast, rather than release-build performance figures.

Please don't. Use a release build or one with a --enable-optimizations. A debug build serves no purpose in benchmarking in general. And please tell me which samples you used.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Doc/library/fnmatch.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Doc/library/fnmatch.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Doc/library/fnmatch.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Doc/library/fnmatch.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 4, 2026
View reviewed changes
Comment thread Lib/test/test_fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
pythongh-160900: document path-like support and test mixed filename t…
e32415c
…ypes
@MonikaDvorackova

MonikaDvorackova commented Nov 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Thanks for the review. I've pushed the documentation updates and added test_mix_bytes_str_pathlike to both FilterTestCase and FilterFalseTestCase. All 28 test_fnmatch tests pass.

I also reran the performance comparison using a CPython 3.16 release build rather than a debug build.

The benchmark compares three implementations:

  • itertools.filterfalse with a lambda predicate
  • A list comprehension
  • An explicit for loop

The input consists of filename strings matched against *.py. I tested input sizes of 10, 100, 1,000, and 10,000 elements, with matching proportions of 0%, 50%, and 100%.

Selected results:

Matches Elements filterfalse + lambda List comprehension Explicit loop
50% 10 1.46 µs 1.17 µs 1.19 µs
50% 100 11.8 µs 10.1 µs 10.3 µs
50% 1,000 115 µs 97.9 µs 98.9 µs
50% 10,000 1.14 ms 966 µs 982 µs

The list comprehension was faster than the lambda-based implementation in 11 of the 12 tested scenarios. However, some measurements showed substantial variability, so these results should be treated as preliminary rather than definitive.

I haven't yet reproduced the benchmark scripts from the original filterfalse PR. I'll check those as well to ensure the comparison covers the original payloads.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 4, 2026

Copy link
Copy Markdown
Member

Please don't use an LLM to post your comments. I don't want to communicate with an agent only. YOur comments are not edited at since the markdown contains the HTML itself.

MonikaDvorackova reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MonikaDvorackova added 2 commits November 4, 2026 17:55
@MonikaDvorackova
Merge branch 'main' into fix/fnmatch-filter-pathlike
5df7949
@MonikaDvorackova
Merge branch 'main' into fix/fnmatch-filter-pathlike
e968f2f
@picnixz

picnixz commented Nov 5, 2026

Copy link
Copy Markdown
Member

Please avoid updating the branches when there is nothing that has changed. It wastes CI resources. Read https://devguide.python.org/getting-started/pull-request-lifecycle/#update-branch-button

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova

MonikaDvorackova commented Nov 5, 2026

Copy link
Copy Markdown
Author

Ok. Thanks for the review. I've addressed the feedback, including the documentation changes and the mixed bytes/str/path-like regression tests.

The latest CI run has completed, with all 51 technical checks passing across the supported platforms.

I also wanted to clarify the earlier branch update: it was intended to retry the macOS CI job after the runner lost communication. I'll avoid unnecessary branch updates going forward.

The PR should now be ready for another review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 5, 2026
View reviewed changes
Comment thread Lib/test/test_fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 5, 2026
View reviewed changes
Comment thread Lib/test/test_fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 5, 2026
View reviewed changes
Comment thread Lib/test/test_fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 5, 2026
View reviewed changes
Comment thread Lib/fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
Address fnmatch review comments
b55db66
@MonikaDvorackova

MonikaDvorackova commented Nov 5, 2026

Copy link
Copy Markdown
Author

I pushed the requested changes in b55db66, including the list comprehension in filter(), and resolved the addressed review threads. Tests, lint, and the documentation preview have all passed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
Preserve POSIX optimization in fnmatch.filter
fac71d6
@MonikaDvorackova

MonikaDvorackova commented Nov 6, 2026

Copy link
Copy Markdown
Author

Ok, sorry I misunderstood. I restored the original POSIX optimization in filter() while retaining PathLike support through os.fspath(). All 28 test_fnmatch tests pass locally.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 6, 2026

Copy link
Copy Markdown
Member

No, the change in filtrr was right. I did not want to change it to a list comprehension unless it is faster. That was the only comment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MonikaDvorackova added 5 commits November 6, 2026 16:29
@MonikaDvorackova
Restore filterfalse POSIX fast path
de8ce43
@MonikaDvorackova
Restore fnmatch test and function spacing
99c9daf
@MonikaDvorackova
Restore fnmatch test and function spacing
ebbadfc
@MonikaDvorackova
Revert unintended follow-up edits
9ab64b5
@MonikaDvorackova
Revert unintended follow-up edits
53e8cd0
picnixz
picnixz reviewed Nov 6, 2026
View reviewed changes
Comment thread Lib/fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 6, 2026
View reviewed changes
Comment thread Lib/test/test_fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 6, 2026
View reviewed changes
Comment thread Lib/fnmatch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@MonikaDvorackova
pythongh-160900: support path-like objects in fnmatch filters
ab8c256
picnixz
picnixz reviewed Nov 8, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-10-30-19-04-37.gh-issue-160900.007288.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

MonikaDvorackova and others added 2 commits November 10, 2026 14:19
@MonikaDvorackova @picnixz
Update Misc/NEWS.d/next/Library/2026-10-30-19-04-37.gh-issue-160900.0…
aa6ccbf
…07288.rst

Co-authored-by: Bénédikt Tran <[email protected]>
@MonikaDvorackova
pythongh-160900: normalize path-like names in filterfalse
6fe66e6
picnixz
picnixz reviewed Nov 10, 2026
View reviewed changes
Comment thread Lib/fnmatch.py Outdated
return result
return [
name for name in names
if match(os.path.normcase(os.fspath(name)))

@picnixz picnixz Nov 10, 2026

Copy link
Copy Markdown
Member

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.

is there a need to call os.fspath?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Nov 10, 2026

Copy link
Copy Markdown
Member

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 thought that os.path.normcase already called os.fspath

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MonikaDvorackova MonikaDvorackova Nov 10, 2026

Copy link
Copy Markdown
Author

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.

You're right, os.path.normcase() already calls os.fspath() on POSIX and Windows. I've removed the redundant calls from both filter() and filterfalse() in 584ec30. test_fnmatch passes locally. Thanks for catching this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@MonikaDvorackova
pythongh-160900: Remove redundant fspath calls
584ec30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fnmatch.filter and filterfalse work with pathlikes only on non-Posix platforms

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@MonikaDvorackova @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.