]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-128520: More consistent type-checking behaviour in pathlib (#130199)
authorBarney Gale <barney.gale@gmail.com>
Fri, 21 Feb 2025 17:47:45 +0000 (17:47 +0000)
committerGitHub <noreply@github.com>
Fri, 21 Feb 2025 17:47:45 +0000 (17:47 +0000)
commitd88677ac20b9466387459d5adb2e87b7de64bc19
tree46b17bbb56b0ecbe01e5596eaaf9b8888388660d
parent286c517db0fedf8d923d6f9620bcbbac4333880d
GH-128520: More consistent type-checking behaviour in pathlib (#130199)

In the following methods, skip casting of the argument to a path object if
the argument has a `with_segments` attribute. In `PurePath`:
`relative_to()`, `is_relative_to()`, `match()`, and `full_match()`. In
`Path`: `rename()`, `replace()`, `copy()`, `copy_into()`, `move()`, and
`move_into()`.

Previously the check varied a bit from method to method. The `PurePath`
methods used `isinstance(arg, PurePath)`; the `rename()` and `replace()`
methods always cast, and the remaining `Path` methods checked for a private
`_copy_writer` attribute.

We apply identical changes to relevant methods of the private ABCs. This
improves performance a bit, because `isinstance()` checks on ABCs are
expensive.
Lib/pathlib/_abc.py
Lib/pathlib/_local.py
Misc/NEWS.d/next/Library/2025-02-16-18-13-40.gh-issue-128520.iZtOMz.rst [new file with mode: 0644]