Skip to content

Add Path.copy_into for 3.14 #13998

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
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions stdlib/@tests/test_cases/check_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from pathlib import Path, PureWindowsPath
from typing_extensions import assert_type


class MyCustomPath(Path): ...


if Path("asdf") == Path("asdf"):
...

Expand All @@ -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)
8 changes: 7 additions & 1 deletion stdlib/pathlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
Loading