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

Fix type annotation in SimplePath.__truediv__ #469

Closed
wants to merge 1 commit into from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 8, 2023

Closes #468

@dimbleby
Copy link
Contributor

shouldn't joinpath agree with __truediv__?

@@ -52,7 +52,7 @@ class SimplePath(Protocol[_T]):
def joinpath(self, other: Union[str, _T]) -> _T:
... # pragma: no cover

def __truediv__(self, other: Union[str, _T]) -> _T:
def __truediv__(self, other: _T) -> _T:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this annotation is correct. A SimplePath could accept a str as input and return a SimplePath. I understand that pathlib.Path is parameterized (the subtype is either str or bytes), but maybe SimplePath should just assume str. The only thing I'm uncertain about is if existing uses might utilize a Path[bytes]. That is, maybe we should eliminate T and replace it with SimplePath... so __truediv__ accepts other: Union[str, 'SimplePath'].

@AlexWaygood
Copy link
Member

FWIW, I think I might have misspoken in python/typeshed#10665 (comment) -- this annotation doesn't look as bad as I thought when I gave my analysis there (which is what prompted Nikita to create this PR). _T should always be solvable for this method, since the whole protocol is generic around the TypeVar, rather than the TypeVar being locally bound to just this method

@jaraco
Copy link
Member

jaraco commented Dec 14, 2023

Based on the discussion, my understanding is that the status quo is probably acceptable and thus we'll choose to reject this change (and its unresolved concerns). Thanks anyhow for the proposal. If you wish to revisit the concern, let's be sure to answer the open concerns about correctness and consistency.

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.

Invalid annotation in SimplePath protocol
4 participants