Skip to content

Commit e4131a5

Browse files
Use absolute path when checking source duplication error (#9059)
Closes #9058. Co-authored-by: Michael Sullivan <[email protected]>
1 parent 48f2b10 commit e4131a5

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

mypy/build.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,7 @@ class State:
16991699
order = None # type: int # Order in which modules were encountered
17001700
id = None # type: str # Fully qualified module name
17011701
path = None # type: Optional[str] # Path to module source
1702+
abspath = None # type: Optional[str] # Absolute path to module source
17021703
xpath = None # type: str # Path or '<string>'
17031704
source = None # type: Optional[str] # Module source code
17041705
source_hash = None # type: Optional[str] # Hash calculated based on the source code
@@ -1800,6 +1801,8 @@ def __init__(self,
18001801
if follow_imports == 'silent':
18011802
self.ignore_all = True
18021803
self.path = path
1804+
if path:
1805+
self.abspath = os.path.abspath(path)
18031806
self.xpath = path or '<string>'
18041807
if path and source is None and self.manager.fscache.isdir(path):
18051808
source = ''
@@ -2758,7 +2761,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
27582761

27592762
# Note: Running this each time could be slow in the daemon. If it's a problem, we
27602763
# can do more work to maintain this incrementally.
2761-
seen_files = {st.path: st for st in graph.values() if st.path}
2764+
seen_files = {st.abspath: st for st in graph.values() if st.path}
27622765

27632766
# Collect dependencies. We go breadth-first.
27642767
# More nodes might get added to new as we go, but that's fine.
@@ -2805,16 +2808,18 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
28052808
if dep in st.dependencies_set:
28062809
st.suppress_dependency(dep)
28072810
else:
2808-
if newst.path in seen_files:
2809-
manager.errors.report(
2810-
-1, 0,
2811-
"Source file found twice under different module names: '{}' and '{}'".
2812-
format(seen_files[newst.path].id, newst.id),
2813-
blocker=True)
2814-
manager.errors.raise_error()
2815-
28162811
if newst.path:
2817-
seen_files[newst.path] = newst
2812+
newst_path = os.path.abspath(newst.path)
2813+
2814+
if newst_path in seen_files:
2815+
manager.errors.report(
2816+
-1, 0,
2817+
"Source file found twice under different module names: "
2818+
"'{}' and '{}'".format(seen_files[newst_path].id, newst.id),
2819+
blocker=True)
2820+
manager.errors.raise_error()
2821+
2822+
seen_files[newst_path] = newst
28182823

28192824
assert newst.id not in graph, newst.id
28202825
graph[newst.id] = newst

0 commit comments

Comments
 (0)