File tree 2 files changed +8
-3
lines changed
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -200,7 +200,12 @@ def class_callable(
200
200
# annotations on __new__ that hardcode the class in the return type.
201
201
# This can then cause problems for subclasses. Preserve the old behaviour in
202
202
# this case (although we should probably change it at some point)
203
- if not is_subtype (default_ret_type , explicit_type , ignore_type_params = True ):
203
+ # See testValueTypeWithNewInParentClass
204
+ # Also see testSelfTypeInGenericClassUsedFromAnotherGenericClass1
205
+ if (
206
+ not is_subtype (default_ret_type , explicit_type , ignore_type_params = True )
207
+ or is_subtype (explicit_type , default_ret_type , ignore_type_params = True )
208
+ ):
204
209
ret_type = explicit_type
205
210
elif (
206
211
# We have to skip protocols, because it can be a subtype of a return type
Original file line number Diff line number Diff line change @@ -6913,8 +6913,8 @@ class O(Generic[T]):
6913
6913
def __new__(cls, x: int = 0) -> O[Any]:
6914
6914
pass
6915
6915
6916
- reveal_type(O()) # N: Revealed type is "__main__.O[Never ]"
6917
- reveal_type(O(10)) # N: Revealed type is "__main__.O[Never ]"
6916
+ reveal_type(O()) # N: Revealed type is "__main__.O[builtins.int ]"
6917
+ reveal_type(O(10)) # N: Revealed type is "__main__.O[builtins.str ]"
6918
6918
6919
6919
[case testNewReturnType6]
6920
6920
from typing import Tuple, Optional
You can’t perform that action at this time.
0 commit comments