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

Improve type annotations (drop python 2?) #117

Open
mfosterw opened this issue Feb 14, 2024 · 0 comments
Open

Improve type annotations (drop python 2?) #117

mfosterw opened this issue Feb 14, 2024 · 0 comments

Comments

@mfosterw
Copy link

mfosterw commented Feb 14, 2024

The collections in this package PatchSet and PatchedFile do not annotate the type of their elements, so iterating over them creates a variable of type Any. For my code, this means either not getting any type hints when working with those elements or manually annotating them when they are accessed (usually by putting a type definition right after the start of a loop).

for file in patchset: # type of 'file' is 'Any'
    file: PatchedFile # type is 'PatchedFile | Any'
    file = cast(PatchedFile, file) # type is 'PatchedFile'

It appears fixing this would require switching to Python 3 type annotations, rather than the current ones which are compatible with Python 2. What are your thoughts on dropping Python 2 support? I understand not wanting to stop supporting any versions, especially for a problem as simple as this one, but it seems to me the value of continuing to support Python 2 is very limited at this point, and continues to fall, and anyone still using it probably isn't updating their packages anyway.

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue May 3, 2024
A pretty simple library. It has inline type comments, so stubgen was able to
write most of the stubs for me.

There is an open issue about switching to inline types (matiasb/python-unidiff#117).
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

No branches or pull requests

1 participant