Skip to content

Commit 21dcd80

Browse files
authored
Fine-grained: Detect changes in additional TypeInfo attributes (#4659)
Detect changes in type variables, generic base classes and the `_promote` attribute. Also one of the new test cases specifically tests semantic analyzer pass 3 when propagating fine-grained dependencies.
1 parent 2833062 commit 21dcd80

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

mypy/server/astdiff.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,22 @@ def snapshot_definition(node: Optional[SymbolNode],
304304
snapshot_optional_type(node.var.type),
305305
snapshot_definition(node.func, common))
306306
elif isinstance(node, TypeInfo):
307-
# TODO:
308-
# type_vars
309-
# bases
310-
# _promote
311307
attrs = (node.is_abstract,
312308
node.is_enum,
313309
node.fallback_to_any,
314310
node.is_named_tuple,
315311
node.is_newtype,
316312
snapshot_optional_type(node.tuple_type),
317313
snapshot_optional_type(node.typeddict_type),
318-
[base.fullname() for base in node.mro])
314+
[base.fullname() for base in node.mro],
315+
node.type_vars,
316+
[snapshot_type(base) for base in node.bases],
317+
snapshot_optional_type(node._promote))
319318
prefix = node.fullname()
320319
symbol_table = snapshot_symbol_table(prefix, node.names)
321320
return ('TypeInfo', common, attrs, symbol_table)
322321
else:
323-
# TODO: Handle additional types: TypeVarExpr, MypyFile, ...
322+
# Other node types are handled elsewhere.
324323
assert False, type(node)
325324

326325

test-data/unit/diff.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,13 @@ B = Dict[str, S]
680680
[out]
681681
__main__.A
682682
__main__.T
683+
684+
[case testChangeGenericBaseClassOnly]
685+
from typing import List
686+
class C(List[int]): pass
687+
[file next.py]
688+
from typing import List
689+
class C(List[str]): pass
690+
[builtins fixtures/list.pyi]
691+
[out]
692+
__main__.C

test-data/unit/fine-grained.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,28 @@ class A: pass
12971297
main:2: error: Module 'a' has no attribute 'A'
12981298
==
12991299

1300+
[case testRefreshGenericAndFailInPass3]
1301+
# Failure in semantic analysis pass 3
1302+
from a import C
1303+
a: C[int]
1304+
[file a.py]
1305+
from typing import TypeVar, Generic
1306+
T = TypeVar('T')
1307+
class C(Generic[T]): pass
1308+
[file a.py.2]
1309+
from typing import TypeVar, Generic
1310+
T = TypeVar('T')
1311+
S = TypeVar('S')
1312+
class C(Generic[T, S]): pass
1313+
[file a.py.3]
1314+
from typing import TypeVar, Generic
1315+
T = TypeVar('T')
1316+
class C(Generic[T]): pass
1317+
[out]
1318+
==
1319+
main:3: error: "C" expects 2 type arguments, but 1 given
1320+
==
1321+
13001322
[case testPrintStatement_python2]
13011323
# flags: --py2
13021324
import a

0 commit comments

Comments
 (0)