PEP 612: Polishing up (#1521)
* making indentation consistent * small alteration to section structure * providing a bit more context for the 'User Defined Generic Classes' section * missing 'and'
This commit is contained in:
parent
5b81f54bd3
commit
d872215d94
24
pep-0612.rst
24
pep-0612.rst
|
@ -148,8 +148,11 @@ type this more complex decorator.
|
|||
Specification
|
||||
-------------
|
||||
|
||||
ParamSpec Declarations
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
``ParamSpec`` Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Declaration
|
||||
````````````
|
||||
|
||||
A parameter specification variable is defined in a similar manner to how a
|
||||
normal type variable is defined with ``typing.TypeVar``.
|
||||
|
@ -165,7 +168,7 @@ arguments in the declaration just as ``typing.TypeVar`` does, but for now we
|
|||
will defer the standardization of the semantics of those options to a later PEP.
|
||||
|
||||
Valid use locations
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
```````````````````
|
||||
|
||||
Previously only a list of parameter arguments (``[A, B, C]``) or an ellipsis
|
||||
(signifying "undefined parameters") were acceptable as the first "argument" to
|
||||
|
@ -179,10 +182,10 @@ parameter specification variable (``Callable[Concatenate[int, P], int]``\ ).
|
|||
|
||||
parameters_expression ::=
|
||||
| "..."
|
||||
| "[" [ type_expression ("," type_expression)\* ] "]"
|
||||
| "[" [ type_expression ("," type_expression)* ] "]"
|
||||
| parameter_specification_variable
|
||||
| concatenate "["
|
||||
type_expression ("," type_expression)\* ","
|
||||
type_expression ("," type_expression)* ","
|
||||
parameter_specification_variable
|
||||
"]"
|
||||
|
||||
|
@ -216,7 +219,8 @@ inheriting from ``Generic[P]`` makes a class generic on
|
|||
P_2 = ParamSpec("P_2")
|
||||
|
||||
class X(Generic[T, P]):
|
||||
...
|
||||
f: Callable[P, int]
|
||||
x: T
|
||||
|
||||
def f(x: X[int, P_2]) -> str: ... # Accepted
|
||||
def f(x: X[int, Concatenate[int, P_2]]) -> str: ... # Accepted
|
||||
|
@ -231,13 +235,17 @@ brackets. For aesthetic purposes we allow these to be omitted.
|
|||
.. code-block::
|
||||
|
||||
class Z(Generic[P]):
|
||||
...
|
||||
f: Callable[P, int]
|
||||
|
||||
def f(x: Z[[int, str, bool]]) -> str: ... # Accepted
|
||||
def f(x: Z[int, str, bool]) -> str: ... # Equivalent
|
||||
|
||||
# Both Z[[int, str, bool]] and Z[int, str, bool] express this:
|
||||
class Z_instantiated:
|
||||
f: Callable[[int, str, bool], int]
|
||||
|
||||
Semantics
|
||||
^^^^^^^^^
|
||||
`````````
|
||||
|
||||
The inference rules for the return type of a function invocation whose signature
|
||||
contains a ``ParamSpec`` variable are analogous to those around
|
||||
|
|
Loading…
Reference in New Issue