diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index 161310ad18bb..83fb0a8cc30b 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -162,7 +162,6 @@ multiprocessing.process.BaseProcess.interrupt multiprocessing.synchronize.SemLock.locked os.__all__ os.readinto -pathlib.Path.copy_into pathlib.Path.copytree pathlib.Path.delete pathlib.Path.info diff --git a/stdlib/@tests/test_cases/check_pathlib.py b/stdlib/@tests/test_cases/check_pathlib.py index 9b4d681c9e96..1ff03c9b8c68 100644 --- a/stdlib/@tests/test_cases/check_pathlib.py +++ b/stdlib/@tests/test_cases/check_pathlib.py @@ -4,6 +4,10 @@ from pathlib import Path, PureWindowsPath from typing_extensions import assert_type + +class MyCustomPath(Path): ... + + if Path("asdf") == Path("asdf"): ... @@ -23,8 +27,14 @@ if sys.version_info >= (3, 13): + pth = MyCustomPath.from_uri("file:///tmp/abc.txt") + assert_type(pth, MyCustomPath) - class MyCustomPath(Path): ... +if sys.version_info >= (3, 14): + my_path = MyCustomPath(".") + pth = my_path.copy_into(Path(".")) + assert_type(pth, Path) - pth = MyCustomPath.from_uri("file:///tmp/abc.txt") + # If the destination is a non-Path, it should default to `Self`. + pth = my_path.copy_into(".") assert_type(pth, MyCustomPath) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index 1e4d97770b7b..7a5b494b70fd 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -15,9 +15,11 @@ from collections.abc import Callable, Generator, Iterator, Sequence from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from os import PathLike, stat_result from types import GenericAlias, TracebackType -from typing import IO, Any, BinaryIO, ClassVar, Literal, overload +from typing import IO, Any, BinaryIO, ClassVar, Literal, TypeVar, overload from typing_extensions import Never, Self, deprecated +_T = TypeVar("_T", bound=PurePath) + __all__ = ["PurePath", "PurePosixPath", "PureWindowsPath", "Path", "PosixPath", "WindowsPath"] if sys.version_info >= (3, 13): @@ -154,6 +156,10 @@ class Path(PurePath): def mkdir(self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False) -> None: ... if sys.version_info >= (3, 14): + @overload + def copy_into(self, target_dir: _T, *, follow_symlinks: bool = True, preserve_metadata: bool = False) -> _T: ... # type: ignore[overload-overlap] + @overload + def copy_into(self, target_dir: StrPath, *, follow_symlinks: bool = True, preserve_metadata: bool = False) -> Self: ... def copy(self, target: StrPath, *, follow_symlinks: bool = True, preserve_metadata: bool = False) -> None: ... def copytree( self,