-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed as not planned
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
In Python 3.12 we've made pathlib.PurePath
subclassable - see #31691.
A significant wrinkle is that subclasses inherit an __fspath__()
method, which can lead to unexpected behaviour when these "pure" paths are passed to filesystem APIs:
import pathlib
class TarPath(pathlib.PurePath):
...
readme = TarPath('README.md', tarfile=...)
with open(readme) as f:
...
The with open(readme) as f:
line should throw a TypeError
, but instead it attempts to open a file called README.md in the current working directory (!). This sort of thing makes subclasses that implement purely virtual filesystems difficult to use safely.
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error