New submission from Cyker Way <[email protected]>:
In short, `fnmatch.fnmatch` doesn't match shell result. To test this, create a
dir with 2 files: `a.py` and `b.py`. Then `ls [!b].py` and `ls [^b].py` will
both show `a.py`. However, `fnmatch.fnmatch('a.py', '[!b].py')` returns `True`
but `fnmatch.fnmatch('a.py', '[^b].py')` returns `False`.
Problem seems to come from an escaped caret:
https://github.com/python/cpython/blob/master/Lib/fnmatch.py#L124
I don't see why caret and exclamation mark are different from `man bash`:
> ...If the first character following the [ is a ! or a ^ then any character
> not enclosed is matched...
Could someone please confirm it's a bug or intended behavior?
----------
components: Library (Lib)
messages: 330417
nosy: cykerway
priority: normal
severity: normal
status: open
title: fnmatch failed with leading caret (^)
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35314>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com