From 5e585d06da972e214883ce5ad1a6419e29d5c273 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:38:16 -0700 Subject: [PATCH 1/2] Fix mypyc error for similar module full names --- mypyc/namegen.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mypyc/namegen.py b/mypyc/namegen.py index 675dae9001c7..ce84fde143d1 100644 --- a/mypyc/namegen.py +++ b/mypyc/namegen.py @@ -100,10 +100,9 @@ def make_module_translation_map(names: list[str]) -> dict[str, str]: for name in names: for suffix in candidate_suffixes(name): if num_instances[suffix] == 1: - result[name] = suffix break - else: - assert False, names + # Takes the last suffix if none are unique + result[name] = suffix return result From 2307850a0e3af0a9e707f91b8bb11f56c1d74e81 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:39:04 -0700 Subject: [PATCH 2/2] Add mypyc test for similar module full names --- mypyc/test/test_namegen.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mypyc/test/test_namegen.py b/mypyc/test/test_namegen.py index 509018b4c3bd..f88edbd00dce 100644 --- a/mypyc/test/test_namegen.py +++ b/mypyc/test/test_namegen.py @@ -35,6 +35,12 @@ def test_make_module_translation_map(self) -> None: "fu.bar": "fu.bar.", "foo.baz": "baz.", } + assert make_module_translation_map(["foo", "foo.foo", "bar.foo", "bar.foo.bar.foo"]) == { + "foo": "foo.", + "foo.foo": "foo.foo.", + "bar.foo": "bar.foo.", + "bar.foo.bar.foo": "foo.bar.foo.", + } def test_name_generator(self) -> None: g = NameGenerator([["foo", "foo.zar"]])