Skip to content

Commit 93b9a38

Browse files
adamtheturtleclaude
andcommitted
Mark TypeVar/ParamSpec/TypeVarTuple 'name' as positional-only
These special-form constructors require `name` to be a positional string literal (PEP 484 / 612 / 646); type checkers reject the keyword form, e.g. mypy: error: TypeVar() expects a string literal as first argument [misc] The stubs advertised `name` as positional-or-keyword, which misleads tools that consume typeshed as ground truth. No type-checker behaviour changes (these are special-cased); the runtime objects are C-level with no introspectable signature on 3.12+, so stubtest is unaffected there. Refs #15804 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5372bd5 commit 93b9a38

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

stdlib/typing.pyi

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class TypeVar:
178178
def __new__(
179179
cls,
180180
name: str,
181+
/,
181182
*constraints: Any, # AnnotationForm
182183
bound: Any | None = None, # AnnotationForm
183184
contravariant: bool = False,
@@ -189,6 +190,7 @@ class TypeVar:
189190
def __new__(
190191
cls,
191192
name: str,
193+
/,
192194
*constraints: Any, # AnnotationForm
193195
bound: Any | None = None, # AnnotationForm
194196
covariant: bool = False,
@@ -199,6 +201,7 @@ class TypeVar:
199201
def __new__(
200202
cls,
201203
name: str,
204+
/,
202205
*constraints: Any, # AnnotationForm
203206
bound: Any | None = None, # AnnotationForm
204207
covariant: bool = False,
@@ -208,6 +211,7 @@ class TypeVar:
208211
def __init__(
209212
self,
210213
name: str,
214+
/,
211215
*constraints: Any, # AnnotationForm
212216
bound: Any | None = None, # AnnotationForm
213217
covariant: bool = False,
@@ -280,6 +284,7 @@ if sys.version_info >= (3, 11):
280284
def __new__(
281285
cls,
282286
name: str,
287+
/,
283288
*,
284289
bound: Any | None = None, # AnnotationForm
285290
covariant: bool = False,
@@ -288,11 +293,11 @@ if sys.version_info >= (3, 11):
288293
infer_variance: bool = False,
289294
) -> Self: ...
290295
elif sys.version_info >= (3, 13):
291-
def __new__(cls, name: str, *, default: Any = ...) -> Self: ... # AnnotationForm
296+
def __new__(cls, name: str, /, *, default: Any = ...) -> Self: ... # AnnotationForm
292297
elif sys.version_info >= (3, 12):
293-
def __new__(cls, name: str) -> Self: ...
298+
def __new__(cls, name: str, /) -> Self: ...
294299
else:
295-
def __init__(self, name: str) -> None: ...
300+
def __init__(self, name: str, /) -> None: ...
296301

297302
def __iter__(self) -> Any: ...
298303
def __typing_subst__(self, arg: Never, /) -> Never: ...
@@ -345,6 +350,7 @@ class ParamSpec:
345350
def __new__(
346351
cls,
347352
name: str,
353+
/,
348354
*,
349355
bound: Any | None = None, # AnnotationForm
350356
contravariant: bool = False,
@@ -356,6 +362,7 @@ class ParamSpec:
356362
def __new__(
357363
cls,
358364
name: str,
365+
/,
359366
*,
360367
bound: Any | None = None, # AnnotationForm
361368
contravariant: bool = False,
@@ -364,11 +371,11 @@ class ParamSpec:
364371
) -> Self: ...
365372
elif sys.version_info >= (3, 11):
366373
def __new__(
367-
cls, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False # AnnotationForm
374+
cls, name: str, /, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False # AnnotationForm
368375
) -> Self: ...
369376
else:
370377
def __init__(
371-
self, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False # AnnotationForm
378+
self, name: str, /, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False # AnnotationForm
372379
) -> None: ...
373380

374381
@property

0 commit comments

Comments
 (0)