[issue30413] Add fnmatch.filter_false function

2017-05-21 Thread Wolfgang Maier

Wolfgang Maier added the comment:

@serhiy: my bad! I just hadn't realized this behavior of the original.
With this requirement I cannot see any simpler solution than Steven's.

Some other questions though to everyone involved:
1) what do you think about "os.path is posixpath" vs just checking os.name == 
'posix' as I suggested earlier?

2) speaking of missing functionality in filter:
What do you think of a keyword argument like 'case' to both filter and 
filterfalse that, when True, would make these functions behave equivalently to
[n for n in names if fnmatchcase(n, pattern)]
The default would be False, of course. I know this would be inconsistent in 
terms of argument vs separate functions, but it is easy to explain and learn 
and without it Windows users of filter/filterfalse would really suffer from the 
much poorer performance due to the slow normcase call (even slower now with the 
new fspath protocol) even if they pass in normalized names already.

3) not directly related to this issue, but I came across it in this context:

isn't normcase in both posixpath and ntpath doing isinstance(str, bytes) checks 
that are redundant with os.fspath? Is this oversight or am I missing something 
again?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Steven D'Aprano

Steven D'Aprano added the comment:

I'm happy for you to change the name to filterfalse.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
components: +Library (Lib)
dependencies: +Improve fnmatch testing

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Yes, it does so only if normalize_case is True. Currently fnmatch.filter() 
returns non-normalized names.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Wolfgang Maier

Wolfgang Maier added the comment:

Does it? I thought it does so only if normalize_case is True.
Did I miss something?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Your patch makes filter() returning normalized names. This may be not what is 
expected.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Wolfgang Maier

Wolfgang Maier added the comment:

Hi,
seems I had the same thoughts as you, Steven. I had started working on a patch 
independently yesterday, but after making my changes to fnmatch itself, I found 
I had too many other things to do to address unittests and doc changes to turn 
this into a real patch - so thank you for spending time on all of this.
I just downloaded your patch and merged it with mine because I think my version 
of fnmatch.py may be simpler and slightly faster (though like you I didn't run 
performance tests). Feel free to do whatever you like with this alternate 
version - it's not that there is much new in it to take credit for :)

Another thing I noted: fnmatch takes a rather unusual approach to determine 
whether normcase is NOP or not. It imports posixpath only to see if it is the 
same as os.path. That looks pretty weird and wasteful to me (especially if you 
are running this on Windows and are effectively importing posixpath just for 
fun then). I think it would be better to just check os.name instead (like 
pathlib does for example). I moved the corresponding check to the top of the 
module to make this easier to address, should that be of interest. I'm also 
using the result of the check in fnmatch.fnmatch because I don't see any reason 
why you wouldn't want to benefit from it there as well.

--
nosy: +wolma
Added file: http://bugs.python.org/file46880/filterfalse.alternate_patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

In general LGTM. I left few minor comments on Rietveld. Needed the versionadded 
directive, Misc/NEWS and What's New entries.

But shouldn't the new function have name "filterfalse" for parallel with 
itertools.filterfalse? And this would better match the style of the fnmatch 
module, fnmatchcase doesn't contain an underscore.

Tests for fnmatch.filter are too poor. I think we should add more tests (this 
is other issue).

--
nosy: +serhiy.storchaka
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30413] Add fnmatch.filter_false function

2017-05-20 Thread Steven D'Aprano

New submission from Steven D'Aprano:

There has been some discussion on Python-Ideas about adding 
fnmatch.filter_false to complement filter, for when you want to ignore matching 
files rather than non-matching ones.

https://mail.python.org/pipermail/python-ideas/2017-May/045694.html

I don't believe there have been any strong objections, and work-arounds have a 
considerable performance penalty (according to the OP, I have not confirmed 
that).

Here's a patch which refactors filter and adds filter_false.

Sorry I haven't got my head around the brave new world on Github, so I'm going 
old school here with a diff :-)

--
files: filterfalse.diff
keywords: patch
messages: 294029
nosy: steven.daprano
priority: normal
severity: normal
status: open
title: Add fnmatch.filter_false function
type: enhancement
versions: Python 3.7
Added file: http://bugs.python.org/file46879/filterfalse.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com