-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-74598: add fnmatch.filterfalse
for excluding names
#121185
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
Conversation
fnmatch.filterfalse
for excluding patternsfnmatch.filterfalse
for excluding names
FT failure is known so I'll wait until the fix (#130724) is merged. |
… feat/fnmatch/filterfalse-74598
…h/filterfalse-74598
I'm going to run some benchmarks again and then I'll merge this one. The feature can still be useful and maintenance is not that hard. If, however, benchmarks are not good, I'll write a recipe instead. |
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 did have other plans for fnmatch
, for supporting complex filters with multiple positive and negative patterns, this is why I was not particularly interested in this feature. But I don't think that adding filterfalse()
is wrong. It will not conflict with future features, and they will not make it obsolete.
LGTM. But please add more tests for filterfalse()
similar to other filter()
tests in FilterTestCase
. The code is completely separate, so we need to test all this.
Will do! |
In this implementation, I did not use a lambda function as it was proposed in the original patch nor did I use auxiliary functions.
EDIT 07/04/2025: I kept the use of
filterfalse
as on a PGO build the loop variant was much slower when processing past a certain number of files. For < 10 files, the numbers are roughly the same and in the range of nanoseconds so we don't really care.Benchmark script
📚 Documentation preview 📚: https://cpython-previews--121185.org.readthedocs.build/