Skip to content

Commit 5b3280e

Browse files
sobolevnhauntsaninja
authored andcommitted
Fix crash on ErasedType and covers_at_runtime (#11924)
Closes #11913 Refs #11273 Co-authored-by: Shantanu <[email protected]>
1 parent 73de602 commit 5b3280e

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Diff for: mypy/erasetype.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def visit_uninhabited_type(self, t: UninhabitedType) -> ProperType:
4141
return t
4242

4343
def visit_erased_type(self, t: ErasedType) -> ProperType:
44-
# Should not get here.
45-
raise RuntimeError()
44+
return t
4645

4746
def visit_partial_type(self, t: PartialType) -> ProperType:
4847
# Should not get here.

Diff for: mypy/subtypes.py

+1
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ def restrict_subtype_away(t: Type, s: Type, *, ignore_promotions: bool = False)
11711171
def covers_at_runtime(item: Type, supertype: Type, ignore_promotions: bool) -> bool:
11721172
"""Will isinstance(item, supertype) always return True at runtime?"""
11731173
item = get_proper_type(item)
1174+
supertype = get_proper_type(supertype)
11741175

11751176
# Since runtime type checks will ignore type arguments, erase the types.
11761177
supertype = erase_type(supertype)

Diff for: test-data/unit/check-inference.test

+15
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,21 @@ def test(seq: List[Union[Iterable, Any]]) -> None:
32113211
reveal_type(k) # N: Revealed type is "builtins.list[Any]"
32123212
[builtins fixtures/list.pyi]
32133213

3214+
[case testErasedTypeRuntimeCoverage]
3215+
# https://github.com/python/mypy/issues/11913
3216+
from typing import TypeVar, Type, Generic, Callable, Iterable
3217+
3218+
class DataType: ...
3219+
3220+
T1 = TypeVar('T1')
3221+
T2 = TypeVar("T2", bound=DataType)
3222+
3223+
def map(__func: T1) -> None: ...
3224+
3225+
def collection_from_dict_value(model: Type[T2]) -> None:
3226+
map(lambda i: i if isinstance(i, model) else i)
3227+
[builtins fixtures/isinstancelist.pyi]
3228+
32143229
[case testRegression11705_Strict]
32153230
# flags: --strict-optional
32163231
# See: https://github.com/python/mypy/issues/11705

0 commit comments

Comments
 (0)