Skip to content

Commit 480efbb

Browse files
committed
Misc
1 parent 84bede2 commit 480efbb

File tree

8 files changed

+54
-15
lines changed

8 files changed

+54
-15
lines changed

mypy/fixup.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def visit_class_def(self, c: ClassDef) -> None:
161161
value.accept(self.type_fixer)
162162
v.upper_bound.accept(self.type_fixer)
163163
v.default.accept(self.type_fixer)
164+
if isinstance(v, ParamSpecType):
165+
v.upper_bound.accept(self.type_fixer)
166+
v.default.accept(self.type_fixer)
167+
if isinstance(v, TypeVarTupleType):
168+
v.upper_bound.accept(self.type_fixer)
169+
v.default.accept(self.type_fixer)
164170

165171
def visit_type_var_expr(self, tv: TypeVarExpr) -> None:
166172
for value in tv.values:
@@ -170,9 +176,11 @@ def visit_type_var_expr(self, tv: TypeVarExpr) -> None:
170176

171177
def visit_paramspec_expr(self, p: ParamSpecExpr) -> None:
172178
p.upper_bound.accept(self.type_fixer)
179+
p.default.accept(self.type_fixer)
173180

174181
def visit_type_var_tuple_expr(self, tv: TypeVarTupleExpr) -> None:
175182
tv.upper_bound.accept(self.type_fixer)
183+
tv.default.accept(self.type_fixer)
176184

177185
def visit_var(self, v: Var) -> None:
178186
if self.current_info is not None:
@@ -294,16 +302,16 @@ def visit_type_var(self, tvt: TypeVarType) -> None:
294302
if tvt.values:
295303
for vt in tvt.values:
296304
vt.accept(self)
297-
if tvt.upper_bound is not None:
298-
tvt.upper_bound.accept(self)
299-
if tvt.default is not None:
300-
tvt.default.accept(self)
305+
tvt.upper_bound.accept(self)
306+
tvt.default.accept(self)
301307

302308
def visit_param_spec(self, p: ParamSpecType) -> None:
303309
p.upper_bound.accept(self)
310+
p.default.accept(self)
304311

305312
def visit_type_var_tuple(self, t: TypeVarTupleType) -> None:
306313
t.upper_bound.accept(self)
314+
t.default.accept(self)
307315

308316
def visit_unpack_type(self, u: UnpackType) -> None:
309317
u.type.accept(self)

mypy/indirection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def visit_type_var(self, t: types.TypeVarType) -> set[str]:
6767
return self._visit(t.values) | self._visit(t.upper_bound) | self._visit(t.default)
6868

6969
def visit_param_spec(self, t: types.ParamSpecType) -> set[str]:
70-
return set()
70+
return self._visit(t.upper_bound) | self._visit(t.default)
7171

7272
def visit_type_var_tuple(self, t: types.TypeVarTupleType) -> set[str]:
73-
return self._visit(t.upper_bound)
73+
return self._visit(t.upper_bound) | self._visit(t.default)
7474

7575
def visit_unpack_type(self, t: types.UnpackType) -> set[str]:
7676
return t.type.accept(self)

mypy/server/astdiff.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,19 @@ def snapshot_symbol_table(name_prefix: str, table: SymbolTable) -> dict[str, Sym
200200
snapshot_optional_type(node.target),
201201
)
202202
elif isinstance(node, ParamSpecExpr):
203-
result[name] = ("ParamSpec", node.variance, snapshot_type(node.upper_bound))
203+
result[name] = (
204+
"ParamSpec",
205+
node.variance,
206+
snapshot_type(node.upper_bound),
207+
snapshot_type(node.default),
208+
)
204209
elif isinstance(node, TypeVarTupleExpr):
205-
result[name] = ("TypeVarTuple", node.variance, snapshot_type(node.upper_bound))
210+
result[name] = (
211+
"TypeVarTuple",
212+
node.variance,
213+
snapshot_type(node.upper_bound),
214+
snapshot_type(node.default),
215+
)
206216
else:
207217
assert symbol.kind != UNBOUND_IMPORTED
208218
if node and get_prefix(node.fullname) != name_prefix:
@@ -386,6 +396,7 @@ def visit_param_spec(self, typ: ParamSpecType) -> SnapshotItem:
386396
typ.id.meta_level,
387397
typ.flavor,
388398
snapshot_type(typ.upper_bound),
399+
snapshot_type(typ.default),
389400
)
390401

391402
def visit_type_var_tuple(self, typ: TypeVarTupleType) -> SnapshotItem:
@@ -394,6 +405,7 @@ def visit_type_var_tuple(self, typ: TypeVarTupleType) -> SnapshotItem:
394405
typ.id.raw_id,
395406
typ.id.meta_level,
396407
snapshot_type(typ.upper_bound),
408+
snapshot_type(typ.default),
397409
)
398410

399411
def visit_unpack_type(self, typ: UnpackType) -> SnapshotItem:

mypy/server/astmerge.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ def process_type_var_def(self, tv: TypeVarType) -> None:
253253
self.fixup_type(tv.upper_bound)
254254
self.fixup_type(tv.default)
255255

256+
def process_param_spec_def(self, tv: ParamSpecType) -> None:
257+
self.fixup_type(tv.upper_bound)
258+
self.fixup_type(tv.default)
259+
260+
def process_type_var_tuple_def(self, tv: TypeVarTupleType) -> None:
261+
self.fixup_type(tv.upper_bound)
262+
self.fixup_type(tv.default)
263+
256264
def visit_assignment_stmt(self, node: AssignmentStmt) -> None:
257265
self.fixup_type(node.type)
258266
super().visit_assignment_stmt(node)
@@ -479,14 +487,17 @@ def visit_type_type(self, typ: TypeType) -> None:
479487

480488
def visit_type_var(self, typ: TypeVarType) -> None:
481489
typ.upper_bound.accept(self)
490+
typ.default.accept(self)
482491
for value in typ.values:
483492
value.accept(self)
484493

485494
def visit_param_spec(self, typ: ParamSpecType) -> None:
486-
pass
495+
typ.upper_bound.accept(self)
496+
typ.default.accept(self)
487497

488498
def visit_type_var_tuple(self, typ: TypeVarTupleType) -> None:
489499
typ.upper_bound.accept(self)
500+
typ.default.accept(self)
490501

491502
def visit_unpack_type(self, typ: UnpackType) -> None:
492503
typ.type.accept(self)

mypy/server/deps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,21 @@ def visit_param_spec(self, typ: ParamSpecType) -> list[str]:
10491049
triggers = []
10501050
if typ.fullname:
10511051
triggers.append(make_trigger(typ.fullname))
1052+
if typ.upper_bound:
1053+
triggers.append(self.get_type_triggers(typ.upper_bound))
1054+
if typ.default:
1055+
triggers.extend(self.get_type_triggers(typ.default))
10521056
triggers.extend(self.get_type_triggers(typ.upper_bound))
10531057
return triggers
10541058

10551059
def visit_type_var_tuple(self, typ: TypeVarTupleType) -> list[str]:
10561060
triggers = []
10571061
if typ.fullname:
10581062
triggers.append(make_trigger(typ.fullname))
1063+
if typ.upper_bound:
1064+
triggers.extend(self.get_type_triggers(typ.upper_bound))
1065+
if typ.default:
1066+
triggers.extend(self.get_type_triggers(typ.default))
10591067
triggers.extend(self.get_type_triggers(typ.upper_bound))
10601068
return triggers
10611069

mypy/type_visitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def visit_param_spec(self, t: ParamSpecType) -> T:
356356
return self.query_types([t.default])
357357

358358
def visit_type_var_tuple(self, t: TypeVarTupleType) -> T:
359-
return self.query_types([t.default])
359+
return self.query_types([t.upper_bound, t.default])
360360

361361
def visit_unpack_type(self, t: UnpackType) -> T:
362362
return self.query_types([t.type])
@@ -490,10 +490,10 @@ def visit_type_var(self, t: TypeVarType) -> bool:
490490
return self.query_types([t.upper_bound, t.default] + t.values)
491491

492492
def visit_param_spec(self, t: ParamSpecType) -> bool:
493-
return t.default.accept(self)
493+
return self.query_types([t.upper_bound, t.default])
494494

495495
def visit_type_var_tuple(self, t: TypeVarTupleType) -> bool:
496-
return t.default.accept(self)
496+
return self.query_types([t.upper_bound, t.default])
497497

498498
def visit_unpack_type(self, t: UnpackType) -> bool:
499499
return self.query_types([t.type])

mypy/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ class TypeVarLikeType(ProperType):
521521
fullname: str # Fully qualified name
522522
id: TypeVarId
523523
upper_bound: Type
524+
default: Type
524525

525526
def __init__(
526527
self,

mypy/typeshed/stdlib/typing.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,11 @@ Any = object()
133133
class TypeVar:
134134
__name__: str
135135
__bound__: Any | None
136-
__default__: Any
137136
__constraints__: tuple[Any, ...]
138137
__covariant__: bool
139138
__contravariant__: bool
140139
def __init__(
141-
self, name: str, *constraints: Any, bound: Any | None = ..., default: Any = ..., covariant: bool = ..., contravariant: bool = ...
140+
self, name: str, *constraints: Any, bound: Any | None = ..., covariant: bool = ..., contravariant: bool = ...
142141
) -> None: ...
143142
if sys.version_info >= (3, 10):
144143
def __or__(self, right: Any) -> _SpecialForm: ...
@@ -216,7 +215,7 @@ if sys.version_info >= (3, 10):
216215
__bound__: Any | None
217216
__covariant__: bool
218217
__contravariant__: bool
219-
def __init__(self, name: str, *, bound: Any | None = ..., default: Any = ..., contravariant: bool = ..., covariant: bool = ...) -> None: ...
218+
def __init__(self, name: str, *, bound: Any | None = ..., contravariant: bool = ..., covariant: bool = ...) -> None: ...
220219
@property
221220
def args(self) -> ParamSpecArgs: ...
222221
@property

0 commit comments

Comments
 (0)