File tree Expand file tree Collapse file tree 3 files changed +5
-5
lines changed Expand file tree Collapse file tree 3 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -197,9 +197,9 @@ def class_callable(
197
197
# by accident. Like `Hashable` is a subtype of `object`. See #11799
198
198
and isinstance (default_ret_type , Instance )
199
199
and not default_ret_type .type .is_protocol
200
- # Only use the declared return type from __new__ or declared self in __init__
200
+ # Only use the declared return type from declared self in __init__
201
201
# if it is actually returning a subtype of what we would return otherwise.
202
- and is_subtype (explicit_type , default_ret_type , ignore_type_params = True )
202
+ and ( is_new or is_subtype (explicit_type , default_ret_type , ignore_type_params = True ) )
203
203
):
204
204
ret_type : Type = explicit_type
205
205
else :
Original file line number Diff line number Diff line change @@ -6883,7 +6883,7 @@ class A:
6883
6883
def __new__(cls) -> int: # E: Incompatible return type for "__new__" (returns "int", but must return a subtype of "A")
6884
6884
pass
6885
6885
6886
- reveal_type(A()) # N: Revealed type is "__main__.A "
6886
+ reveal_type(A()) # N: Revealed type is "builtins.int "
6887
6887
6888
6888
[case testNewReturnType4]
6889
6889
from typing import TypeVar, Type
@@ -6960,7 +6960,7 @@ class A:
6960
6960
class B(A):
6961
6961
pass
6962
6962
6963
- reveal_type(B()) # N: Revealed type is "__main__.B "
6963
+ reveal_type(B()) # N: Revealed type is "__main__.A "
6964
6964
6965
6965
[case testNewReturnType10]
6966
6966
# https://github.com/python/mypy/issues/11398
Original file line number Diff line number Diff line change @@ -1360,7 +1360,7 @@ class Bar(Foo):
1360
1360
A = 1
1361
1361
B = 2
1362
1362
1363
- a = Bar.A
1363
+ a = Bar.A # E: "Type[Foo]" has no attribute "A"
1364
1364
reveal_type(a.value) # N: Revealed type is "Any"
1365
1365
reveal_type(a._value_) # N: Revealed type is "Any"
1366
1366
[builtins fixtures/primitives.pyi]
You can’t perform that action at this time.
0 commit comments