Skip to content

Commit e43b1f8

Browse files
committed
Misc
1 parent a8212dd commit e43b1f8

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
@@ -172,6 +172,12 @@ def visit_class_def(self, c: ClassDef) -> None:
172172
value.accept(self.type_fixer)
173173
v.upper_bound.accept(self.type_fixer)
174174
v.default.accept(self.type_fixer)
175+
if isinstance(v, ParamSpecType):
176+
v.upper_bound.accept(self.type_fixer)
177+
v.default.accept(self.type_fixer)
178+
if isinstance(v, TypeVarTupleType):
179+
v.upper_bound.accept(self.type_fixer)
180+
v.default.accept(self.type_fixer)
175181

176182
def visit_type_var_expr(self, tv: TypeVarExpr) -> None:
177183
for value in tv.values:
@@ -181,9 +187,11 @@ def visit_type_var_expr(self, tv: TypeVarExpr) -> None:
181187

182188
def visit_paramspec_expr(self, p: ParamSpecExpr) -> None:
183189
p.upper_bound.accept(self.type_fixer)
190+
p.default.accept(self.type_fixer)
184191

185192
def visit_type_var_tuple_expr(self, tv: TypeVarTupleExpr) -> None:
186193
tv.upper_bound.accept(self.type_fixer)
194+
tv.default.accept(self.type_fixer)
187195

188196
def visit_var(self, v: Var) -> None:
189197
if self.current_info is not None:
@@ -305,16 +313,16 @@ def visit_type_var(self, tvt: TypeVarType) -> None:
305313
if tvt.values:
306314
for vt in tvt.values:
307315
vt.accept(self)
308-
if tvt.upper_bound is not None:
309-
tvt.upper_bound.accept(self)
310-
if tvt.default is not None:
311-
tvt.default.accept(self)
316+
tvt.upper_bound.accept(self)
317+
tvt.default.accept(self)
312318

313319
def visit_param_spec(self, p: ParamSpecType) -> None:
314320
p.upper_bound.accept(self)
321+
p.default.accept(self)
315322

316323
def visit_type_var_tuple(self, t: TypeVarTupleType) -> None:
317324
t.upper_bound.accept(self)
325+
t.default.accept(self)
318326

319327
def visit_unpack_type(self, u: UnpackType) -> None:
320328
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
@@ -201,9 +201,19 @@ def snapshot_symbol_table(name_prefix: str, table: SymbolTable) -> dict[str, Sym
201201
snapshot_optional_type(node.target),
202202
)
203203
elif isinstance(node, ParamSpecExpr):
204-
result[name] = ("ParamSpec", node.variance, snapshot_type(node.upper_bound))
204+
result[name] = (
205+
"ParamSpec",
206+
node.variance,
207+
snapshot_type(node.upper_bound),
208+
snapshot_type(node.default),
209+
)
205210
elif isinstance(node, TypeVarTupleExpr):
206-
result[name] = ("TypeVarTuple", node.variance, snapshot_type(node.upper_bound))
211+
result[name] = (
212+
"TypeVarTuple",
213+
node.variance,
214+
snapshot_type(node.upper_bound),
215+
snapshot_type(node.default),
216+
)
207217
else:
208218
assert symbol.kind != UNBOUND_IMPORTED
209219
if node and get_prefix(node.fullname) != name_prefix:
@@ -394,6 +404,7 @@ def visit_param_spec(self, typ: ParamSpecType) -> SnapshotItem:
394404
typ.id.meta_level,
395405
typ.flavor,
396406
snapshot_type(typ.upper_bound),
407+
snapshot_type(typ.default),
397408
)
398409

399410
def visit_type_var_tuple(self, typ: TypeVarTupleType) -> SnapshotItem:
@@ -402,6 +413,7 @@ def visit_type_var_tuple(self, typ: TypeVarTupleType) -> SnapshotItem:
402413
typ.id.raw_id,
403414
typ.id.meta_level,
404415
snapshot_type(typ.upper_bound),
416+
snapshot_type(typ.default),
405417
)
406418

407419
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
@@ -252,6 +252,14 @@ def process_type_var_def(self, tv: TypeVarType) -> None:
252252
self.fixup_type(tv.upper_bound)
253253
self.fixup_type(tv.default)
254254

255+
def process_param_spec_def(self, tv: ParamSpecType) -> None:
256+
self.fixup_type(tv.upper_bound)
257+
self.fixup_type(tv.default)
258+
259+
def process_type_var_tuple_def(self, tv: TypeVarTupleType) -> None:
260+
self.fixup_type(tv.upper_bound)
261+
self.fixup_type(tv.default)
262+
255263
def visit_assignment_stmt(self, node: AssignmentStmt) -> None:
256264
self.fixup_type(node.type)
257265
super().visit_assignment_stmt(node)
@@ -478,14 +486,17 @@ def visit_type_type(self, typ: TypeType) -> None:
478486

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

484493
def visit_param_spec(self, typ: ParamSpecType) -> None:
485-
pass
494+
typ.upper_bound.accept(self)
495+
typ.default.accept(self)
486496

487497
def visit_type_var_tuple(self, typ: TypeVarTupleType) -> None:
488498
typ.upper_bound.accept(self)
499+
typ.default.accept(self)
489500

490501
def visit_unpack_type(self, typ: UnpackType) -> None:
491502
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
@@ -352,7 +352,7 @@ def visit_param_spec(self, t: ParamSpecType) -> T:
352352
return self.query_types([t.default])
353353

354354
def visit_type_var_tuple(self, t: TypeVarTupleType) -> T:
355-
return self.query_types([t.default])
355+
return self.query_types([t.upper_bound, t.default])
356356

357357
def visit_unpack_type(self, t: UnpackType) -> T:
358358
return self.query_types([t.type])
@@ -483,10 +483,10 @@ def visit_type_var(self, t: TypeVarType) -> bool:
483483
return self.query_types([t.upper_bound, t.default] + t.values)
484484

485485
def visit_param_spec(self, t: ParamSpecType) -> bool:
486-
return t.default.accept(self)
486+
return self.query_types([t.upper_bound, t.default])
487487

488488
def visit_type_var_tuple(self, t: TypeVarTupleType) -> bool:
489-
return t.default.accept(self)
489+
return self.query_types([t.upper_bound, t.default])
490490

491491
def visit_unpack_type(self, t: UnpackType) -> bool:
492492
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
@@ -138,12 +138,11 @@ Any = object()
138138
class TypeVar:
139139
__name__: str
140140
__bound__: Any | None
141-
__default__: Any
142141
__constraints__: tuple[Any, ...]
143142
__covariant__: bool
144143
__contravariant__: bool
145144
def __init__(
146-
self, name: str, *constraints: Any, bound: Any | None = None, default: Any | None = None, covariant: bool = False, contravariant: bool = False
145+
self, name: str, *constraints: Any, bound: Any | None = None, covariant: bool = False, contravariant: bool = False
147146
) -> None: ...
148147
if sys.version_info >= (3, 10):
149148
def __or__(self, right: Any) -> _SpecialForm: ...
@@ -222,7 +221,7 @@ if sys.version_info >= (3, 10):
222221
__covariant__: bool
223222
__contravariant__: bool
224223
def __init__(
225-
self, name: str, *, bound: Any | None = None, default: Any | None = None, contravariant: bool = False, covariant: bool = False
224+
self, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False
226225
) -> None: ...
227226
@property
228227
def args(self) -> ParamSpecArgs: ...

0 commit comments

Comments
 (0)