Skip to content

Pattern matching uses regex feature available only in Python 3.11+ #8

Closed

Description

@barneygale

Pathlib's implementation of matching/globbing uses possessive quantifiers, which are new in Python 3.11. This package should support 3.8+, so we need to find another solution.

Activity

  1. barneygale commented on Dec 22, 2023

    @barneygale
    OwnerAuthor

    Fix via Alex Waygood:

    diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
    index 43e2670c4d..98823b7274 100644
    --- a/Lib/pathlib/_abc.py
    +++ b/Lib/pathlib/_abc.py
    @@ -64,7 +64,7 @@ def _compile_pattern(pat, sep, case_sensitive):
         regex = glob.translate(pat, recursive=True, include_hidden=True, seps=sep)
         # The string representation of an empty path is a single dot ('.'). Empty
         # paths shouldn't match wildcards, so we consume it with an atomic group.
    -    regex = r'(\.\Z)?+' + regex
    +    regex = r'(?=(?P<empty>\.\Z|))(?P=empty)' + regex
         return re.compile(regex, flags=flags).match
     
     
  2. added this to the v1.0.0 milestone on Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions