You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are you reporting a bug, or opening a feature request?
Encountered an unexpected behavior (bug?) when working with classmethods on generics. It is also possible that I have misunderstood how this is supposed to work.
Please insert below the code you are checking with mypy,
Here is a minimal example:
T=TypeVar('T')
Self=TypeVar('Self', bound='Foo')
classFoo(Generic[T]):
a: Tdef__init__(self, a: T) ->None:
self.a=a@classmethoddefoof(cls: Type[Self], a: T) ->Self:
returncls(a)
classBaz(Foo[str]):
@classmethoddefoof(cls, a: str) ->'Baz': # error: Return type "Baz" of "oof" incompatible with return type <nothing> in supertype "Foo"returncls(a)
What is the actual behavior/output?
With mypy==0.720, this generates:
error: Return type "Baz" of "oof" incompatible with return type
What is the behavior/output you expect?
Given that
classBaz(Foo[str]):
passreveal_type(Baz.oof('1')) # note: Revealed type is 'ack.Baz*'
I would expect there to be no error when I override the classmethod in the subclass, so long as it is not conflicting.
I believe that this is technically a false positive. However, requiring the use of self types in all overrides seems kind of reasonable to me, so I wouldn't classify this as a bug but a missing feature.
The motivation for the check is that there could be a subclass of Baz that inherits oof from Baz, in which case mypy would be correct to complain (and incorrect to not complain). However, I think that this error condition could only be reported if there actually is a subclass of Baz that doesn't override oof.
Are you reporting a bug, or opening a feature request?
Encountered an unexpected behavior (bug?) when working with classmethods on generics. It is also possible that I have misunderstood how this is supposed to work.
Please insert below the code you are checking with mypy,
Here is a minimal example:
What is the actual behavior/output?
With
mypy==0.720
, this generates:What is the behavior/output you expect?
Given that
I would expect there to be no error when I override the classmethod in the subclass, so long as it is not conflicting.
On the other hand, I can work around this by
Have been spending some time looking at #6418 and related issues.
The text was updated successfully, but these errors were encountered: