Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-110109: Drop use of new regex features inpathlib._abc.#113292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@barneygale
Copy link
Contributor

@barneygalebarneygale commentedDec 19, 2023
edited
Loading

A regex group with a?+ possessive quantifier was used to match empty paths, which were represented as a single dot, preventing the dot from being matched by other wildcards. This quantifier is only available from Python 3.11+, but pathlib's_abc.py file will be made available as a PyPI package for Python 3.8+.

This commit adds a new private_pattern_str property that works like__str__() but represents empty paths as'' rather than'.'. This string is used for pattern matching, which removes the need for the possessive group. We also replacere.NOFLAG with0, again for backwards-compatibility with older Python.

Improves compatibility with older Python; no other change of behaviour.

See externalpathlib_abc issue:barneygale/pathlib-abc#8

A regex group with a `?+` possessive quantifier was used to match emptypaths, which were represented as a single dot, preventing the dot frombeing matched by other wildcards. This quantifier is only available fromPython 3.11+, but pathlib's `_abc.py` file will be made available as a PyPIpackage for Python 3.8+.This commit adds a new private `_pattern_str` property that works like`__str__()` but represents empty paths as `''` rather than `'.'`. Thisstring is used for pattern matching, which removes the need for thepossessive group.Improves compatibility with older Python; no other change of behaviour.
@barneygale
Copy link
ContributorAuthor

I think this is slower, but only very slightly:

$ ./python -m timeit -s"from pathlib import Path; p = Path('foo.py')""p.match('*.py')"50000 loops, best of 5: 4.75 usec per loop# before50000 loops, best of 5: 4.81 usec per loop# after$ ./python -m timeit -s"from pathlib import Path""list(Path.cwd().glob('**/*', follow_symlinks=True))"5 loops, best of 5: 81 msec per loop# before5 loops, best of 5: 81 msec per loop# after

@barneygale
Copy link
ContributorAuthor

@AlexWaygood pointed me towardsthis video, which shows how to implement atomic groups/posessive qualifiers in older Python using a capturing lookahead and a backref. It's a one-line patch so I'll apply it only in the externalpathlib_abc package. Withdrawing this PR.

AlexWaygood reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@barneygale

[8]ページ先頭

©2009-2025 Movatter.jp