Skip to content

Commit

Permalink
Fix crash related to AST diff of ParamSpec in mypy daemon (#11567)
Browse files Browse the repository at this point in the history
Fixes #11566.
  • Loading branch information
JukkaL committed Nov 16, 2021
1 parent 9a34e6c commit 8a58b22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mypy/server/astdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class level -- these are handled at attribute level (say, 'mod.Cls.method'

from mypy.nodes import (
SymbolTable, TypeInfo, Var, SymbolNode, Decorator, TypeVarExpr, TypeAlias,
FuncBase, OverloadedFuncDef, FuncItem, MypyFile, UNBOUND_IMPORTED
FuncBase, OverloadedFuncDef, FuncItem, MypyFile, ParamSpecExpr, UNBOUND_IMPORTED
)
from mypy.types import (
Type, TypeVisitor, UnboundType, AnyType, NoneType, UninhabitedType,
Expand Down Expand Up @@ -151,6 +151,10 @@ def snapshot_symbol_table(name_prefix: str, table: SymbolTable) -> Dict[str, Sna
node.normalized,
node.no_args,
snapshot_optional_type(node.target))
elif isinstance(node, ParamSpecExpr):
result[name] = ('ParamSpec',
node.variance,
snapshot_type(node.upper_bound))
else:
assert symbol.kind != UNBOUND_IMPORTED
if node and get_prefix(node.fullname) != name_prefix:
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/diff.test
Original file line number Diff line number Diff line change
Expand Up @@ -1470,3 +1470,17 @@ x: Union[Callable[[Arg(int, 'y')], None],
[builtins fixtures/tuple.pyi]
[out]
__main__.x

[case testChangeParamSpec]
from typing import ParamSpec, TypeVar
A = ParamSpec('A')
B = ParamSpec('B')
C = TypeVar('C')
[file next.py]
from typing import ParamSpec, TypeVar
A = ParamSpec('A')
B = TypeVar('B')
C = ParamSpec('C')
[out]
__main__.B
__main__.C

0 comments on commit 8a58b22

Please sign in to comment.