Skip to content

Call to super() is flagged with an error in function but not in classmethod #8604

Closed Answered by erictraut
danpascu asked this question in Q&A
Discussion options

You must be logged in to vote

In a class method, if you don't specify a type annotation for the cls parameter, it implicitly has the type type[Self]. This is analogous to the self parameter in an instance method, which implicitly has the type Self.

In your function _alt_creat_2, the type of cls is annotated to be type[T] where T is bound to Structure. This is not the same as type[Self@Structure]. That explains why you're seeing a difference in behavior.

I'll need to think more about whether it's safe from a type perspective to support what you're doing here. At first glance, it seems like it should be. The question is then whether it's worth attempting to enhance the handling of super in pyright to support this. The l…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@erictraut
Comment options

Answer selected by danpascu
Comment options

You must be logged in to vote
1 reply
@danpascu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants