From a313ee27396ed03ff5a37e0d63f83d6fae2101c0 Mon Sep 17 00:00:00 2001 From: William Bruns Date: Sun, 13 Sep 2026 01:10:10 +0000 Subject: [PATCH] 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 ) --- Doc/reference/compound_stmts.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index c13860eb3e9319..8ed57b7cc8bdb9 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -1849,17 +1849,17 @@ The following example indicates the full set of allowed type parameter declarati def overly_generic[ SimpleTypeVar, - TypeVarWithDefault = int, TypeVarWithBound: int, TypeVarWithConstraints: (str, bytes), - *SimpleTypeVarTuple = (int, float), - **SimpleParamSpec = (str, bytearray), + TypeVarWithDefault = int, + *SimpleTypeVarTuple = *tuple[int, float], + **SimpleParamSpec = [str, bytearray], ]( a: SimpleTypeVar, - b: TypeVarWithDefault, - c: TypeVarWithBound, - d: Callable[SimpleParamSpec, TypeVarWithConstraints], - *e: SimpleTypeVarTuple, + b: TypeVarWithBound, + c: Callable[SimpleParamSpec, TypeVarWithConstraints], + d: TypeVarWithDefault, + *e: *SimpleTypeVarTuple, ): ... .. _generic-functions: