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 signature construction for overload + implicit classmethod #9921

Merged
merged 1 commit into from
Jan 18, 2021

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jan 17, 2021

__class_getitem__ and __init_subclass__ are always classmethods, even if
they aren't decorated. We previously only handled this correctly if
these methods weren't overloaded.

This came up in python/typeshed#4937

__class_getitem__ and __init_subclass__ are always classmethods, even if
they aren't decorated. We previously only handled this correctly if
these methods weren't overloaded.

This came up in python/typeshed#4937
if name in ("__init_subclass__", "__class_getitem__"):
# These are implicitly classmethods. If the stub chooses not to have @classmethod, we
# should remove the cls argument
if args[0].variable.name == "cls":
Copy link
Member

Choose a reason for hiding this comment

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

What if I name it _cls instead? It sounds like we should just unconditionally remove the first arg.

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Jan 18, 2021

Choose a reason for hiding this comment

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

Unconditionally removing the first argument here isn't right, because it'll do the wrong thing if you do choose to decorate with @classmethod, since those get their first argument stripped when resolving the decorator.

I don't think this is important enough to figure out how to chain enough state to keep track of that.

Especially since stubtest currently is picky about classmethod names being cls, e.g. this not-actually-needed-potentially-problematic assert when resolving the classmethod decorator:

assert func.arguments[0].variable.name in ("cls", "metacls")

@JelleZijlstra JelleZijlstra merged commit 734e4ad into python:master Jan 18, 2021
@hauntsaninja hauntsaninja deleted the stubover branch January 18, 2021 01:26
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.

2 participants