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
from __future__ importannotationsclassA:
def__new__(cls) ->B:
returnB()
classB(A):
passclassC(A):
passvar1=A()
reveal_type(var1) # Revealed type is "B", as exceptedvar2=C()
reveal_type(var2) # Revealed type is "C", should be "B" (pyright reports "B")
I suspect this is due to the fact that __new__ should return a subclass of the class being defined according to mypy. I think it is a reasonable idea (see #1020 (comment)) to allow arbitrary types to be allowed, altough this might not be considered a good practice. A use case can be found here (the linked PR above is trying to implement stubs for this).
Activity
intgr commentedon Jan 12, 2023
I also found issue #8330 which seems to ask for the same thing.
Viicos commentedon Jan 12, 2023
Good catch, guess I missed it when searching for similar issues. Closing in favor of this one