Skip to content

Commit 13c9484

Browse files
Fix ParamSpec ellipsis default for <3.10 (#279)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 4705e74 commit 13c9484

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
called on a concrete subclass of a generic class. Patch by Alex Waygood
66
(backporting https://github.com/python/cpython/pull/107584, by James
77
Hilton-Balfe).
8+
- Fix bug where `ParamSpec(default=...)` would raise a `TypeError` on Python
9+
versions <3.11. Patch by James Hilton-Balfe
810

911
# Release 4.7.1 (July 2, 2023)
1012

doc/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ Special typing primitives
278278

279279
The implementation was changed for compatibility with Python 3.12.
280280

281+
.. versionchanged:: 4.8.0
282+
283+
Passing an ellipsis literal (``...``) to *default* now works on Python
284+
3.10 and lower.
285+
281286
.. class:: ParamSpecArgs
282287

283288
.. class:: ParamSpecKwargs

src/test_typing_extensions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5593,6 +5593,9 @@ def test_paramspec(self):
55935593
class A(Generic[P]): ...
55945594
Alias = typing.Callable[P, None]
55955595

5596+
P_default = ParamSpec('P_default', default=...)
5597+
self.assertIs(P_default.__default__, ...)
5598+
55965599
def test_typevartuple(self):
55975600
Ts = TypeVarTuple('Ts', default=Unpack[Tuple[str, int]])
55985601
self.assertEqual(Ts.__default__, Unpack[Tuple[str, int]])

src/typing_extensions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,10 @@ def _set_default(type_param, default):
12771277
type_param.__default__ = tuple((typing._type_check(d, "Default must be a type")
12781278
for d in default))
12791279
elif default != _marker:
1280-
type_param.__default__ = typing._type_check(default, "Default must be a type")
1280+
if isinstance(type_param, ParamSpec) and default is ...: # ... not valid <3.11
1281+
type_param.__default__ = default
1282+
else:
1283+
type_param.__default__ = typing._type_check(default, "Default must be a type")
12811284
else:
12821285
type_param.__default__ = None
12831286

0 commit comments

Comments
 (0)