Skip to content

Commit 2bd91d5

Browse files
committed
more changes
1 parent e2d3a5e commit 2bd91d5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mypy/typeops.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ def class_callable(
200200
# annotations on __new__ that hardcode the class in the return type.
201201
# This can then cause problems for subclasses. Preserve the old behaviour in
202202
# 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+
):
204209
ret_type = explicit_type
205210
elif (
206211
# We have to skip protocols, because it can be a subtype of a return type

test-data/unit/check-classes.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -6913,8 +6913,8 @@ class O(Generic[T]):
69136913
def __new__(cls, x: int = 0) -> O[Any]:
69146914
pass
69156915

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]"
69186918

69196919
[case testNewReturnType6]
69206920
from typing import Tuple, Optional

0 commit comments

Comments
 (0)