Skip to content

Conversation

@barneygale
Copy link
Contributor

@barneygale barneygale commented Feb 16, 2025

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 checked isinstance(arg, PurePath); the rename() and replace() methods always cast, and the remaining Path methods checked for a private arg._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.

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.
@barneygale barneygale merged commit d88677a into python:main Feb 21, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant