Skip to content

Add missing dependency from missing module attribute #5861

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

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/server/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,15 @@ def visit_member_expr(self, e: MemberExpr) -> None:
# Reference to a module attribute
self.process_global_ref_expr(e)
else:
# Reference to a non-module attribute
# Reference to a non-module (or missing) attribute
if e.expr not in self.type_map:
# No type available -- this happens for unreachable code. Since it's unreachable,
# it wasn't type checked and we don't need to generate dependencies.
return
if isinstance(e.expr, RefExpr) and isinstance(e.expr.node, MypyFile):
# Special case: reference to a missing module attribute.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also update the comment few lines above (can't comment there):

# Reference to a non-module attribute -> # Reference to a non-module (or missing) attribute

self.add_dependency(make_trigger(e.expr.node.fullname() + '.' + e.name))
return
typ = self.type_map[e.expr]
self.add_attribute_dependency(typ, e.name)
if self.use_logical_deps() and isinstance(typ, AnyType):
Expand Down
41 changes: 41 additions & 0 deletions test-data/unit/deps.test
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,47 @@ def f(x: A) -> None:
<m.A> -> <m.f>, m.f
<p.b.A> -> m

[case testIgnoredMissingModuleAttribute]
import a
a.x # type: ignore

import b.c
b.c.x # type: ignore

from b import c
c.y # type: ignore
[file a.py]
[file b/__init__.py]
[file b/c.py]
[builtins fixtures/module.pyi]
[out]
<a.x> -> m
<a> -> m
<b.c.x> -> m
<b.c.y> -> m
<b.c> -> m
<b> -> m

[case testIgnoredMissingInstanceAttribute]
from a import C
C().x # type: ignore
[file a.py]
class C: pass
[out]
<a.C.__init__> -> m
<a.C.__new__> -> m
<a.C.x> -> m
<a.C> -> m

[case testIgnoredMissingClassAttribute]
from a import C
C.x # type: ignore
[file a.py]
class C: pass
[out]
<a.C.x> -> m
<a.C> -> m

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a fine grained test too, so that it will not regress for other (non dependency caused) reasons.

[case testDepsFromOverloadMod]
# __dump_all__
import mod
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -2125,3 +2125,20 @@ def f(x: str) -> None: pass
[out]
==
main.py:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"

[case testIgnoredAttrReprocessedModule]
import a
[file a.py]
import b
x = b.x # type: ignore
y: int = x
[file b.py]
import c
[file b.py.2]
import c
x = c.x
[file c.py]
x: str
[out]
==
a.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int")