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

stubtest: fix false-positive error for Protocol __init__s and Protocol __annotations__ #13179

Merged
merged 2 commits into from
Jul 20, 2022

Conversation

AlexWaygood
Copy link
Member

Fixes #12820

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Should this check whether runtime.__init__ is Protocol.__init__? E.g., given python/cpython#31628

@AlexWaygood
Copy link
Member Author

Should this check whether runtime.__init__ is Protocol.__init__? E.g., given python/cpython#31628

I sank some time into this, but I think it might be more trouble than it's worth. The check would be much more complicated than a simple runtime.__init__ is Protocol.__init__ check, due to the fact that there's some pretty cursed stuff going on at runtime with Protocol __init__ methods: https://github.com/python/cpython/blob/3f738600f623b88bc90ec12587f75babb6f1025e/Lib/typing.py#L2086-L2087. The fact that this logic changed in 3.11 to mean that now Protocol __init__s are only sometimes replaced (rather than being replaced all the time) makes it even more complicated.

It's probably doable, but would you accept this patch as-is for now, with a TODO comment saying that we should probably check __init__ in some situations on 3.11+?

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jul 19, 2022

Yup, I'd merge a TODO!

@AlexWaygood AlexWaygood changed the title stubtest: fix false-positive error for Protocol __init__s stubtest: fix false-positive error for Protocol __init__s and Protocol __annotations__ Jul 19, 2022
@AlexWaygood
Copy link
Member Author

AlexWaygood commented Jul 19, 2022

The output if I run typeshed's stubtest_stdlib.py with this patch applied (on Python 3.10, on my Windows PC):

+note: unused allowlist entry importlib.abc.Traversable.__init__
+note: unused allowlist entry importlib.metadata.PackageMetadata.__init__
+note: unused allowlist entry importlib.metadata._meta.PackageMetadata.__init__
+note: unused allowlist entry importlib.metadata._meta.SimplePath.__init__
+note: unused allowlist entry typing.SupportsAbs.__init__
+note: unused allowlist entry typing.SupportsBytes.__init__
+note: unused allowlist entry typing.SupportsComplex.__init__
+note: unused allowlist entry typing.SupportsFloat.__init__
+note: unused allowlist entry typing.SupportsIndex.__init__
+note: unused allowlist entry typing.SupportsInt.__init__
+note: unused allowlist entry typing.SupportsRound.__init__

@hauntsaninja hauntsaninja merged commit 53465bd into python:master Jul 20, 2022
@AlexWaygood AlexWaygood deleted the stubtest-proto branch July 20, 2022 06:56
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.

stubtest false positive for Protocol __init__
2 participants