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

super() erroneously flagged as incorrect when cls function parameter is generic #7690

Closed
wadetregaskis-linkedin opened this issue Oct 11, 2019 · 4 comments

Comments

@wadetregaskis-linkedin
Copy link

from typing import Type, TypeVar

T = TypeVar('T', bound='BaseClass')

class BaseClass:
    pass

class SubClass(BaseClass):
    @classmethod
    def foo(cls: Type[T]) -> None:
        super().bar()

mypy 0.730 newly (vs 0.720) reports the false error:

error: Argument 2 for "super" not an instance of argument 1

@wadetregaskis-linkedin
Copy link
Author

(ignoring that in this contrived, condensed example there is no bar - in my real code there's no such issues and it definitely works as intended at runtime irrespective of mypy's opinions)

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 11, 2019

The error message is confusing, but I think that mypy is technically correct. The bound for T should be SubClass, not BaseClass.

@wadetregaskis-linkedin
Copy link
Author

Hmm, perhaps my example is missing some pertinent details. In my actual use, bar is a method defined in BaseClass, and foo is overriding the implementation from BaseClass. As such it needs to preserve the method signature of the original method, which is to return an instance of the generic T.

@AlexWaygood
Copy link
Member

I'm closing this issue in favour of #9282 (a newer issue, but it has a lot more discussion attached to it, and it's the same behaviour on display)

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

3 participants