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:
Mark Mendoza 2020-07-13 13:11:38 -07:00 committed by GitHub
parent 5b81f54bd3
commit d872215d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 67 additions and 59 deletions

View File

@ -148,8 +148,11 @@ type this more complex decorator.
Specification Specification
------------- -------------
ParamSpec Declarations ``ParamSpec`` Variables
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
Declaration
````````````
A parameter specification variable is defined in a similar manner to how a A parameter specification variable is defined in a similar manner to how a
normal type variable is defined with ``typing.TypeVar``. 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. will defer the standardization of the semantics of those options to a later PEP.
Valid use locations Valid use locations
^^^^^^^^^^^^^^^^^^^ ```````````````````
Previously only a list of parameter arguments (``[A, B, C]``) or an ellipsis Previously only a list of parameter arguments (``[A, B, C]``) or an ellipsis
(signifying "undefined parameters") were acceptable as the first "argument" to (signifying "undefined parameters") were acceptable as the first "argument" to
@ -179,10 +182,10 @@ parameter specification variable (``Callable[Concatenate[int, P], int]``\ ).
parameters_expression ::= parameters_expression ::=
| "..." | "..."
| "[" [ type_expression ("," type_expression)\* ] "]" | "[" [ type_expression ("," type_expression)* ] "]"
| parameter_specification_variable | parameter_specification_variable
| concatenate "[" | concatenate "["
type_expression ("," type_expression)\* "," type_expression ("," type_expression)* ","
parameter_specification_variable parameter_specification_variable
"]" "]"
@ -216,7 +219,8 @@ inheriting from ``Generic[P]`` makes a class generic on
P_2 = ParamSpec("P_2") P_2 = ParamSpec("P_2")
class X(Generic[T, P]): 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, P_2]) -> str: ... # Accepted
def f(x: X[int, Concatenate[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:: .. code-block::
class Z(Generic[P]): 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: ... # Accepted
def f(x: Z[int, str, bool]) -> str: ... # Equivalent 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 Semantics
^^^^^^^^^ `````````
The inference rules for the return type of a function invocation whose signature The inference rules for the return type of a function invocation whose signature
contains a ``ParamSpec`` variable are analogous to those around contains a ``ParamSpec`` variable are analogous to those around