8000 `PurePath.match` accepts a `PurePath` pattern only since Python 3.12 · Issue #112758 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

PurePath.match accepts a PurePath pattern only since Python 3.12 #112758

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vlopezferrando opened this issue Dec 5, 2023 · 4 comments
Closed
Labels
3.12 only security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir topic-pathlib

Comments

@vlopezferrando
Copy link
vlopezferrando commented Dec 5, 2023

Documentation

In the docs on PurePath.match(pattern, *, case_sensitive=None) on pathlib, it says:

The pattern may be another path object; this speeds up matching the same pattern against multiple files:

But it doesn't say that pattern can only be a path object since Python 3.12.

For example, on Python 3.11, you get this error when trying to use a PurePath as the pattern:

Python 3.11.6 (main, Oct 18 2023, 12:13:43) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import PurePath
>>> pattern = PurePath("*.py")
>>> PurePath("hello.py").match(pattern)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/victor/.pyenv/versions/3.11.6/lib/python3.11/pathlib.py", line 810, in match
    drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/victor/.pyenv/versions/3.11.6/lib/python3.11/pathlib.py", line 67, in parse_parts
    drv, root, rel = self.splitroot(part)
                     ^^^^^^^^^^^^^^^^^^^^
  File "/home/victor/.pyenv/versions/3.11.6/lib/python3.11/pathlib.py", line 240, in splitroot
    if part and part[0] == sep:
                ~~~~^^^
TypeError: 'PurePosixPath' object is not subscriptable
>>> vim /home/victor/.pyenv/versions/3.11.6/lib/python3.11/pathlib.py
  File "<stdin>", line 1
    vim /home/victor/.pyenv/versions/3.11.6/lib/python3.11/pathlib.py
                     ^
SyntaxError: invalid syntax
>>> :810
  File "<stdin>", line 1
    :810
    ^
SyntaxError: invalid syntax
>>>

Linked PRs

@vlopezferrando vlopezferrando added the docs Documentation in the Doc dir label Dec 5, 2023
@Eclips4 Eclips4 added topic-pathlib 3.12 only security fixes 3.13 bugs and security fixes labels Dec 5, 2023
@tpackard1
Copy link
Contributor

Hi @vlopezferrando
I would like to work on a PR for this issue unless you are already working on it?

@vlopezferrando
Copy link
Author

@tpackard1 Sure, go ahead!

@tpackard1
Copy link
Contributor

Thanks @vlopezferrando! I am working on a PR for this right now and should be done with it in a few hours.

@barneygale
Copy link
Contributor

Thanks @vlopezferrando for the crystal-clear bug report, and @tpackard1 for promptly fixing it. Resolving this issue!

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 8, 2023
…thonGH-112814)

(cherry picked from commit ed8720a)

Co-authored-by: Taylor Packard <3.t.packard@gmail.com>
barneygale pushed a commit that referenced this issue Dec 8, 2023
…H-112814) (#112882)

gh-112758: Updated pathlib documentation for PurePath.match (GH-112814)
(cherry picked from commit ed8720a)

Co-authored-by: Taylor Packard <3.t.packard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir topic-pathlib
Projects
None yet
Development

No branches or pull requests

4 participants
0