Skip to content

Commit 51a017d

Browse files
committed
Some code review tweaks
1 parent 839d912 commit 51a017d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

mypyc/genops.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,12 @@ def prepare_class_def(path: str, module_name: str, cdef: ClassDef,
595595
ir.inherits_python = True
596596
continue
597597
base_ir = mapper.type_to_ir[cls]
598-
if not base_ir.is_ext_class:
599-
ir.inherits_python = True
600598
if not base_ir.is_trait:
601599
base_mro.append(base_ir)
602600
mro.append(base_ir)
603601

604-
# Generic and similar are python base classes
605-
if cdef.removed_base_type_exprs:
606-
ir.inherits_python = True
602+
if cls.defn.removed_base_type_exprs or not base_ir.is_ext_class::
603+
ir.inherits_python = True
607604

608605
base_idx = 1 if not ir.is_trait else 0
609606
if len(base_mro) > base_idx:

mypyc/test-data/run-classes.test

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ except TypeError as e:
10341034

10351035
[case testPickling]
10361036
from mypy_extensions import trait
1037-
from typing import Any
1037+
from typing import Any, TypeVar, Generic
10381038

10391039
def dec(x: Any) -> Any:
10401040
return x
@@ -1070,8 +1070,17 @@ class D:
10701070
class E(D):
10711071
y: int
10721072

1073+
1074+
U = TypeVar('U')
1075+
1076+
class F(Generic[U]):
1077+
y: int
1078+
1079+
class G(F[int]):
1080+
pass
1081+
10731082
[file driver.py]
1074-
from native import A, B, T, C, D, E
1083+
from native import A, B, T, C, D, E, F, G
10751084

10761085
import copy
10771086
import pickle
@@ -1082,19 +1091,21 @@ assert T.__mypyc_attrs__ == ('a',)
10821091
assert C.__mypyc_attrs__ == ('w', 'z', 'x', 'y', 'a')
10831092
assert not hasattr(D, '__mypyc_attrs__')
10841093
assert E.__mypyc_attrs__ == ('y', '__dict__')
1094+
assert F.__mypyc_attrs__ == ('y', '__dict__')
1095+
assert G.__mypyc_attrs__ == ('y', '__dict__')
10851096

10861097
b = B(10, '20', False)
10871098
assert b.__getstate__() == {'z': False, 'x': 10, 'y': '20'}
10881099
b2 = copy.copy(b)
1089-
assert b != b2 and b.y == b2.y
1100+
assert b is not b2 and b.y == b2.y
10901101

10911102
b3 = pickle.loads(pickle.dumps(b))
1092-
assert b != b3 and b.y == b3.y
1103+
assert b is not b3 and b.y == b3.y
10931104

10941105
e = E()
10951106
e.x = 10
10961107
e.y = 20
10971108

10981109
assert e.__getstate__() == {'y': 20, '__dict__': {'x': 10}}
10991110
e2 = pickle.loads(pickle.dumps(e))
1100-
assert e != e2 and e.x == e2.x and e.y == e2.y
1111+
assert e is not e2 and e.x == e2.x and e.y == e2.y

0 commit comments

Comments
 (0)