Skip to content

Commit a313ee2

Browse files
committed
Fix the Compound Statement 'overly_generic' example's Python SyntaxError, and type annotation errors (ParamSpec default given as a tuple (instead of List), TypeVarTuple default specified as a plain packed tuple instead of unpacked) by prior author
Re: the 'Compound Statement's 'overly_generic' example on https://docs.python.org/3.16/reference/compound_stmts.html (archived as is at https://web.archive.org/web/20260913010111/https://docs.python.org/3.16/reference/compound_stmts.html ) (and docs for earlier Python versions, e.g. 3.13, 3.14, 3.15), this commit: - Fixes Python 'SyntaxError': 'non-default type parameter \'TypeVarWithBound\' follows default type parameter for the overly_generic' by moving the 'TypeVarwithDefault' down in the list after the non-default type parameters (from https://github.com/python/cpython/blob/fe3a26f43fad1d6eed20172d7f63ee2931ae2ce1/Doc/reference/compound_stmts.rst?plain=1#L1852 ) - Fixes MyPy 'error: The default argument to ParamSpec must be a list expression, ellipsis, or a ParamSpec [misc]' by substituting '**SimpleParamSpec=[str, bytearray]' instead of the invalid '**SimpleParamSpec=[str, bytearray]' (fixing https://github.com/python/cpython/blob/fe3a26f43fad1d6eed20172d7f63ee2931ae2ce1/Doc/reference/compound_stmts.rst?plain=1#L1856 ) to follow guidance at e.g. https://typing.python.org/en/latest/spec/generics.html#paramspec-defaults (archived as is at https://web.archive.org/web/20260913004550/https://typing.python.org/en/latest/spec/generics.html#paramspec-defaults ) - Fixes MyPy 'error: The default argument to TypeVarTuple must be an Unpacked tuple [misc]' by replacing '*SimpleTypeVarTuple = (int, float),' with '*SimpleTypeVarTuple = *tuple[int, float],' (fixing https://github.com/python/cpython/blob/fe3a26f43fad1d6eed20172d7f63ee2931ae2ce1/Doc/reference/compound_stmts.rst?plain=1#L1855 ) to follow guidance at e.g. https://typing.python.org/en/latest/spec/generics.html#typevartuple-defaults (archived as is at https://web.archive.org/web/20260913004550/https://typing.python.org/en/latest/spec/generics.html#typevartuple-defaults ) - Fixes MyPy 'error: TypeVarTuple 'SimpleTypeVarTuple' is only valid with an unpack [valid-type]' by replacing '*e: SimpleTypeVarTuple,' with '*e: *SimpleTypeVarTuple,' to follow guidance at e.g. https://typing.python.org/en/latest/spec/generics.html#args-as-a-type-variable-tuple (archived as is at https://web.archive.org/web/20260913004550/https://typing.python.org/en/latest/spec/generics.html#args-as-a-type-variable-tuple )
1 parent 1a703ab commit a313ee2

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Doc/reference/compound_stmts.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,17 +1849,17 @@ The following example indicates the full set of allowed type parameter declarati
18491849

18501850
def overly_generic[
18511851
SimpleTypeVar,
1852-
TypeVarWithDefault = int,
18531852
TypeVarWithBound: int,
18541853
TypeVarWithConstraints: (str, bytes),
1855-
*SimpleTypeVarTuple = (int, float),
1856-
**SimpleParamSpec = (str, bytearray),
1854+
TypeVarWithDefault = int,
1855+
*SimpleTypeVarTuple = *tuple[int, float],
1856+
**SimpleParamSpec = [str, bytearray],
18571857
](
18581858
a: SimpleTypeVar,
1859-
b: TypeVarWithDefault,
1860-
c: TypeVarWithBound,
1861-
d: Callable[SimpleParamSpec, TypeVarWithConstraints],
1862-
*e: SimpleTypeVarTuple,
1859+
b: TypeVarWithBound,
1860+
c: Callable[SimpleParamSpec, TypeVarWithConstraints],
1861+
d: TypeVarWithDefault,
1862+
*e: *SimpleTypeVarTuple,
18631863
): ...
18641864

18651865
.. _generic-functions:

0 commit comments

Comments
 (0)