Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7ef72d

Browse files
authored
Fix crash on unpacking with invalid base class (#2249)
Fixes #2244.
1 parent b3d0569 commit c7ef72d

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

mypy/maptype.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def map_instance_to_supertypes(instance: Instance,
3636
a.extend(map_instance_to_direct_supertypes(t, sup))
3737
types = a
3838
result.extend(types)
39-
return result
39+
if result:
40+
return result
41+
else:
42+
# Nothing. Presumably due to an error. Construct a dummy using Any.
43+
return [Instance(supertype, [AnyType()] * len(supertype.type_vars))]
4044

4145

4246
def class_derivation_paths(typ: TypeInfo,

test-data/unit/check-classes.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,11 @@ C(0)
14191419
C(arg=0)
14201420
[out]
14211421

1422+
[case testErrorMapToSupertype]
1423+
import typing
1424+
class X(Nope): pass # E: Name 'Nope' is not defined
1425+
a, b = X() # Used to crash here (#2244)
1426+
14221427

14231428
-- Type[C]
14241429
-- -------

0 commit comments

Comments
 (0)