Skip to content

Commit

Permalink
[mypyc] Fix classes with the same name in multi-module mode (#7851)
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan authored Nov 2, 2019
1 parent f6ce23f commit 4b5f33d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mypyc/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from mypy_extensions import trait

from mypyc.namegen import NameGenerator
from mypyc.namegen import NameGenerator, exported_name

T = TypeVar('T')

Expand Down Expand Up @@ -1858,7 +1858,7 @@ def name_prefix(self, names: NameGenerator) -> str:
return names.private_name(self.module_name, self.name)

def struct_name(self, names: NameGenerator) -> str:
return '{}Object'.format(self.name_prefix(names))
return '{}Object'.format(exported_name(self.fullname))

def get_method_and_class(self, name: str) -> Optional[Tuple[FuncIR, 'ClassIR']]:
for ir in self.mro:
Expand Down
5 changes: 5 additions & 0 deletions mypyc/test-data/run-multimodule.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ else:

[case testMultiModuleSameNames]
# Use same names in both modules
import other
def f() -> int:
return 0
class C:
Expand All @@ -40,6 +41,10 @@ class C:
def f(self, x: int) -> int:
return self.x + x
class D(C): pass

def g(x: 'other.C') -> None:
pass

[file other.py]
def f(x: int) -> int:
return x + 1
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test/test_emitfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ def test_list_append(self) -> None:
def test_get_attr(self) -> None:
self.assert_emit(
GetAttr(self.r, 'y', 1),
"""cpy_r_r0 = native_A_gety((AObject *)cpy_r_r); /* y */""")
"""cpy_r_r0 = native_A_gety((mod___AObject *)cpy_r_r); /* y */""")

def test_set_attr(self) -> None:
self.assert_emit(
SetAttr(self.r, 'y', self.m, 1),
"cpy_r_r0 = native_A_sety((AObject *)cpy_r_r, cpy_r_m); /* y */")
"cpy_r_r0 = native_A_sety((mod___AObject *)cpy_r_r, cpy_r_m); /* y */")

def test_dict_get_item(self) -> None:
self.assert_emit(PrimitiveOp([self.d, self.o2], dict_get_item_op, 1),
Expand Down

0 comments on commit 4b5f33d

Please sign in to comment.