Skip to content

Commit

Permalink
Use absolute path when checking source duplication error (#9059)
Browse files Browse the repository at this point in the history
Closes #9058.

Co-authored-by: Michael Sullivan <[email protected]>
  • Loading branch information
bonprosoft and msullivan authored Oct 18, 2020
1 parent 48f2b10 commit e4131a5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,7 @@ class State:
order = None # type: int # Order in which modules were encountered
id = None # type: str # Fully qualified module name
path = None # type: Optional[str] # Path to module source
abspath = None # type: Optional[str] # Absolute path to module source
xpath = None # type: str # Path or '<string>'
source = None # type: Optional[str] # Module source code
source_hash = None # type: Optional[str] # Hash calculated based on the source code
Expand Down Expand Up @@ -1800,6 +1801,8 @@ def __init__(self,
if follow_imports == 'silent':
self.ignore_all = True
self.path = path
if path:
self.abspath = os.path.abspath(path)
self.xpath = path or '<string>'
if path and source is None and self.manager.fscache.isdir(path):
source = ''
Expand Down Expand Up @@ -2758,7 +2761,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,

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

# Collect dependencies. We go breadth-first.
# More nodes might get added to new as we go, but that's fine.
Expand Down Expand Up @@ -2805,16 +2808,18 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
if dep in st.dependencies_set:
st.suppress_dependency(dep)
else:
if newst.path in seen_files:
manager.errors.report(
-1, 0,
"Source file found twice under different module names: '{}' and '{}'".
format(seen_files[newst.path].id, newst.id),
blocker=True)
manager.errors.raise_error()

if newst.path:
seen_files[newst.path] = newst
newst_path = os.path.abspath(newst.path)

if newst_path in seen_files:
manager.errors.report(
-1, 0,
"Source file found twice under different module names: "
"'{}' and '{}'".format(seen_files[newst_path].id, newst.id),
blocker=True)
manager.errors.raise_error()

seen_files[newst_path] = newst

assert newst.id not in graph, newst.id
graph[newst.id] = newst
Expand Down

0 comments on commit e4131a5

Please sign in to comment.