Skip to content
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

Add _BaseSegment to simplify type annotations. #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

udifuchs
Copy link
Contributor

@udifuchs udifuchs commented Mar 1, 2025

_BaseSegment is a private type alias for either PathSegment or Move classes.

It simplifies the type annotations and resolves most of the typing issue.

This commit also fixes the typing issues for slices (as in getitem).

Adding typing for slices make the behaviour of the Path class a bit more official.
Path behaves here a bit differently from most mutable sequences.
For example, a slice of an array is an array:

>>> from array import array
>>> a = array("i", [1, 2, 3])
>>> a[1:2]
array('i', [2])

Therefore it would make sense that a slice of a Path would also be a Path
and not a list.

We could make any usage of slice raise a NotImplementedError.
It would brake backward compatibility, but I would be surprised if anyone
is using slices of Path.

The other option is to apply this PR as is.

_BaseSegment is a private type alias for either PathSegment or Move classes.

It simplifies the type annotations and resolves most of the typing issue.

This commit also fixes the typing issues for slices (as in __getitem__).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant