stdlib: add __slots__ (#14611)

This commit is contained in:
Jelle Zijlstra
2025-08-21 07:24:59 -07:00
committed by GitHub
parent 28abff1eb3
commit f32d9f08bd
38 changed files with 247 additions and 12 deletions
+41 -4
View File
@@ -29,6 +29,31 @@ if sys.version_info >= (3, 13):
__all__ += ["UnsupportedOperation"]
class PurePath(PathLike[str]):
if sys.version_info >= (3, 13):
__slots__ = (
"_raw_paths",
"_drv",
"_root",
"_tail_cached",
"_str",
"_str_normcase_cached",
"_parts_normcase_cached",
"_hash",
)
elif sys.version_info >= (3, 12):
__slots__ = (
"_raw_paths",
"_drv",
"_root",
"_tail_cached",
"_str",
"_str_normcase_cached",
"_parts_normcase_cached",
"_lines_cached",
"_hash",
)
else:
__slots__ = ("_drv", "_root", "_parts", "_str", "_hash", "_pparts", "_cached_cparts")
if sys.version_info >= (3, 13):
parser: ClassVar[types.ModuleType]
def full_match(self, pattern: StrPath, *, case_sensitive: bool | None = None) -> bool: ...
@@ -108,10 +133,19 @@ class PurePath(PathLike[str]):
if sys.version_info >= (3, 12):
def with_segments(self, *args: StrPath) -> Self: ...
class PurePosixPath(PurePath): ...
class PureWindowsPath(PurePath): ...
class PurePosixPath(PurePath):
__slots__ = ()
class PureWindowsPath(PurePath):
__slots__ = ()
class Path(PurePath):
if sys.version_info >= (3, 14):
__slots__ = ("_info",)
elif sys.version_info >= (3, 10):
__slots__ = ()
else:
__slots__ = ("_accessor",)
if sys.version_info >= (3, 12):
def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... # pyright: ignore[reportInconsistentConstructor]
else:
@@ -310,8 +344,11 @@ class Path(PurePath):
self, top_down: bool = True, on_error: Callable[[OSError], object] | None = None, follow_symlinks: bool = False
) -> Iterator[tuple[Self, list[str], list[str]]]: ...
class PosixPath(Path, PurePosixPath): ...
class WindowsPath(Path, PureWindowsPath): ...
class PosixPath(Path, PurePosixPath):
__slots__ = ()
class WindowsPath(Path, PureWindowsPath):
__slots__ = ()
if sys.version_info >= (3, 13):
class UnsupportedOperation(NotImplementedError): ...