Skip to content

Commit

Permalink
Some code review tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Sep 9, 2019
1 parent 839d912 commit 9cbd742
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
7 changes: 2 additions & 5 deletions mypyc/genops.py
Expand Up @@ -595,15 +595,12 @@ def prepare_class_def(path: str, module_name: str, cdef: ClassDef,
ir.inherits_python = True
continue
base_ir = mapper.type_to_ir[cls]
if not base_ir.is_ext_class:
ir.inherits_python = True
if not base_ir.is_trait:
base_mro.append(base_ir)
mro.append(base_ir)

# Generic and similar are python base classes
if cdef.removed_base_type_exprs:
ir.inherits_python = True
if cls.defn.removed_base_type_exprs or not base_ir.is_ext_class:
ir.inherits_python = True

base_idx = 1 if not ir.is_trait else 0
if len(base_mro) > base_idx:
Expand Down
21 changes: 16 additions & 5 deletions mypyc/test-data/run-classes.test
Expand Up @@ -1034,7 +1034,7 @@ except TypeError as e:

[case testPickling]
from mypy_extensions import trait
from typing import Any
from typing import Any, TypeVar, Generic

def dec(x: Any) -> Any:
return x
Expand Down Expand Up @@ -1070,8 +1070,17 @@ class D:
class E(D):
y: int


U = TypeVar('U')

class F(Generic[U]):
y: int

class G(F[int]):
pass

[file driver.py]
from native import A, B, T, C, D, E
from native import A, B, T, C, D, E, F, G

import copy
import pickle
Expand All @@ -1082,19 +1091,21 @@ assert T.__mypyc_attrs__ == ('a',)
assert C.__mypyc_attrs__ == ('w', 'z', 'x', 'y', 'a')
assert not hasattr(D, '__mypyc_attrs__')
assert E.__mypyc_attrs__ == ('y', '__dict__')
assert F.__mypyc_attrs__ == ('y', '__dict__')
assert G.__mypyc_attrs__ == ('y', '__dict__')

b = B(10, '20', False)
assert b.__getstate__() == {'z': False, 'x': 10, 'y': '20'}
b2 = copy.copy(b)
assert b != b2 and b.y == b2.y
assert b is not b2 and b.y == b2.y

b3 = pickle.loads(pickle.dumps(b))
assert b != b3 and b.y == b3.y
assert b is not b3 and b.y == b3.y

e = E()
e.x = 10
e.y = 20

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

0 comments on commit 9cbd742

Please sign in to comment.