Repository navigation
Document exceptions raised by fnmtach #89973
Description
Activity
DimitriPapadopoulos commented
on Nov 16, 2021 DimitriPapadopoulosmannequinMannequinAuthorMore actionsThe fnmatch documentation should explicitly mention the type of exceptions raised by fnmatch.fnmatch():
https://docs.python.org/3/library/fnmatch.htmlIn 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.
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.11only security fixesonly security fixes
on Nov 16, 2021 - addeddocsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 16, 2021 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.
Reacted by MariattaIn what case it raises
re.error?- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Apr 21, 2022 15 remaining items
Still, it would be nice to:
- either document that
fnmatch()might raise are.errorif something goes wrong with pattern processing, - or catch
re.errorexceptions and raise aValueError.
Just in case...
- either document that
- added a commit that references this issue
on May 22, 2022 - added a commit that references this issue
on Jun 26, 2022 - added a commit that references this issue
on Jun 26, 2022 - added a commit that references this issue
on Jun 26, 2022
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs