Skip to content

Fine-grained: Detect changes in additional TypeInfo attributes #4659

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 1 commit into from
Mar 2, 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
11 changes: 5 additions & 6 deletions mypy/server/astdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,22 @@ def snapshot_definition(node: Optional[SymbolNode],
snapshot_optional_type(node.var.type),
snapshot_definition(node.func, common))
elif isinstance(node, TypeInfo):
# TODO:
# type_vars
# bases
# _promote
attrs = (node.is_abstract,
node.is_enum,
node.fallback_to_any,
node.is_named_tuple,
node.is_newtype,
snapshot_optional_type(node.tuple_type),
snapshot_optional_type(node.typeddict_type),
[base.fullname() for base in node.mro])
[base.fullname() for base in node.mro],
node.type_vars,
[snapshot_type(base) for base in node.bases],
snapshot_optional_type(node._promote))
prefix = node.fullname()
symbol_table = snapshot_symbol_table(prefix, node.names)
return ('TypeInfo', common, attrs, symbol_table)
else:
# TODO: Handle additional types: TypeVarExpr, MypyFile, ...
# Other node types are handled elsewhere.
assert False, type(node)


Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/diff.test
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,13 @@ B = Dict[str, S]
[out]
__main__.A
__main__.T

[case testChangeGenericBaseClassOnly]
from typing import List
class C(List[int]): pass
[file next.py]
from typing import List
class C(List[str]): pass
[builtins fixtures/list.pyi]
[out]
__main__.C
22 changes: 22 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,28 @@ class A: pass
main:2: error: Module 'a' has no attribute 'A'
==

[case testRefreshGenericAndFailInPass3]
# Failure in semantic analysis pass 3
from a import C
a: C[int]
[file a.py]
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]): pass
[file a.py.2]
from typing import TypeVar, Generic
T = TypeVar('T')
S = TypeVar('S')
class C(Generic[T, S]): pass
[file a.py.3]
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]): pass
[out]
==
main:3: error: "C" expects 2 type arguments, but 1 given
==

[case testPrintStatement_python2]
# flags: --py2
import a
Expand Down