You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my case it raised sre_constants.error, and it took some time to understand that the proper way to catch this type of exceptions is to catch the re.error superclass, by reading https://bugs.python.org/issue795379.
Actually that would be the case for any module using the re module under the hood, possibly passing an ill-formed regex to a re function.
It'd also be reasonable for the fnmatch._compile_pattern function to be updated to catch re.error and internally and reraise ValueError. The only times this should happen are when the input pattern turns into an invalid regular expression so our code cannot use it. So in absense of us improving fnmatch's abilities, it is an error with the user supplied value.
Or for maximum backwards compatibility, an fnmatch.PatternError class that inherits from both re.error and ValueError so that code can be written to catch either.
Activity
DimitriPapadopoulos commentedon Nov 16, 2021
The fnmatch documentation should explicitly mention the type of exceptions raised by fnmatch.fnmatch():
https://docs.python.org/3/library/fnmatch.html
In my case it raised sre_constants.error, and it took some time to understand that the proper way to catch this type of exceptions is to catch the re.error superclass, by reading https://bugs.python.org/issue795379.
Actually that would be the case for any module using the re module under the hood, possibly passing an ill-formed regex to a re function.
gpshead commentedon Apr 14, 2022
It'd also be reasonable for the
fnmatch._compile_patternfunction to be updated to catchre.errorand internally and reraiseValueError. The only times this should happen are when the input pattern turns into an invalid regular expression so our code cannot use it. So in absense of us improving fnmatch's abilities, it is an error with the user supplied value.Or for maximum backwards compatibility, an fnmatch.PatternError class that inherits from both re.error and ValueError so that code can be written to catch either.
serhiy-storchaka commentedon Apr 15, 2022
In what case it raises
re.error?15 remaining items
DimitriPapadopoulos commentedon May 4, 2022
Still, it would be nice to:
fnmatch()might raise are.errorif something goes wrong with pattern processing,re.errorexceptions and raise aValueError.Just in case...
pythongh-89973: Fix re.error in the fnmatch module.
pythongh-89973: Fix re.error in the fnmatch module. (pythonGH-93072)
gh-89973: Fix re.error in the fnmatch module. (GH-93072)
pythongh-89973: Fix re.error in the fnmatch module. (pythonGH-93072)
gh-89973: Fix re.error in the fnmatch module. (GH-93072)
gh-89973: Fix re.error in the fnmatch module. (GH-93072)
Revert 30935 defer bpo45162 to 312 (#94285)
builtin cover: fix handling of invalid glob ranges with Python 3.10.5+
builtin cover: fix handling of invalid glob ranges with Python 3.10.5+ (