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
Then __get__ is correctly inferred when called directly, but not when called implictly.
classModel:
child1=Child1(null=False)
child1a=Child1(null=True)
reveal_type(Child1(null=False).__get__(None, None)) # Revealed type is "builtins.int"reveal_type(Child1(null=True).__get__(None, None)) # Revealed type is "Union[builtins.int, None]"reveal_type(Model().child1) # Revealed type is "builtins.int"reveal_type(Model().child1a) # Revealed type is "builtins.int" <- INCORRECT
Note that this bug is avoided if the overloads are redefined in the child class.
classChild2(Parent[_T]):
@overloaddef__get__(self: Child2[Literal[False]], instance, owner) ->int: ...
@overloaddef__get__(self: Child2[Literal[True]], instance, owner) ->int|None: ...
classModel:
child2=Child2(null=False)
child2a=Child2(null=True)
reveal_type(Child2(null=False).__get__(None, None)) # Revealed type is "builtins.int"reveal_type(Child2(null=True).__get__(None, None)) # Revealed type is "Union[builtins.int, None]"reveal_type(Model().child2) # Revealed type is "builtins.int"reveal_type(Model().child2a) # Revealed type is "Union[builtins.int, None]" <- CORRECT
Bug Report
Define overloads of
__get__
for a generic class usingself
.Define a child of this class.
Then
__get__
is correctly inferred when called directly, but not when called implictly.Note that this bug is avoided if the overloads are redefined in the child class.
pyright correctly handles this scenario.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.13&gist=c81567a4853ba23e6eab357147b6625b
The text was updated successfully, but these errors were encountered: