Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use absolute path when checking source duplication error #9059

Merged
merged 6 commits into from
Oct 18, 2020
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