Sitelet https://github.com/python/cpython/issues/89973
Skip to content

Document exceptions raised by fnmtach #89973

Description

@DimitriPapadopoulos
BPO 45815
Nosy @ezio-melotti, @DimitriPapadopoulos
Files
  • sre_constants.error_stderr.txt: Last part of the stderr output of a Python script that calls fnmatch() on a bad glob
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2021-11-16.10:46:44.748>
    labels = ['expert-regex', '3.11', 'library', 'docs']
    title = 'Document exceptions raised by fnmtach'
    updated_at = <Date 2021-11-16.10:46:44.748>
    user = 'https://github.com/DimitriPapadopoulos'

    bugs.python.org fields:

    activity = <Date 2021-11-16.10:46:44.748>
    actor = 'DimitriPapadopoulosOrfanos'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Library (Lib)', 'Regular Expressions']
    creation = <Date 2021-11-16.10:46:44.748>
    creator = 'DimitriPapadopoulosOrfanos'
    dependencies = []
    files = ['50442']
    hgrepos = []
    issue_num = 45815
    keywords = []
    message_count = 1.0
    messages = ['406396']
    nosy_count = 4.0
    nosy_names = ['ezio.melotti', 'mrabarnett', 'docs@python', 'DimitriPapadopoulosOrfanos']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue45815'
    versions = ['Python 3.11']

    Linked PRs

    Activity

    1. DimitriPapadopoulos commented on Nov 16, 2021

      DimitriPapadopoulosmannequin
      MannequinAuthor

      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.

    2. added
      docsDocumentation in the Doc dir
      stdlibStandard Library Python modules in the Lib/ directory
      3.11only security fixes
      on Nov 16, 2021
    3. transferred this issue fromon Apr 10, 2022
    4. gpshead commented on Apr 14, 2022

      @gpshead
      Member

      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.

    5. serhiy-storchaka commented on Apr 15, 2022

      @serhiy-storchaka
      Member

      In what case it raises re.error?

    6. 15 remaining items

    7. DimitriPapadopoulos commented on May 4, 2022

      @DimitriPapadopoulos
      Author

      Still, it would be nice to:

      • either document that fnmatch() might raise a re.error if something goes wrong with pattern processing,
      • or catch re.error exceptions and raise a ValueError.

      Just in case...

    8. added a commit that references this issue on May 22, 2022
    9. Repository owner moved this from In Progress to Done in Fnmatch and glob issueson Jun 5, 2022
    10. added a commit that references this issue on Jun 5, 2022
    11. added a commit that references this issue on Jun 5, 2022
    12. added 3 commits that reference this issue on Jun 5, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    3.10 (EOL)end of life3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-regex

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions