-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtopic-pathlib
Description
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
barneygale and tpackard1
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtopic-pathlib