[issue44791] Substitution of ParamSpec in Concatenate
Ken Jin
report at bugs.python.org
Sat Jul 31 12:21:23 EDT 2021
Ken Jin <kenjin4096 at gmail.com> added the comment:
Should Concatenate support substitution to begin with? PEP 612 doesn't say anything, and I am fairly certain it's a special typing form, not a generic. So I don't really understand what it means to substitute Concatenate.
Then again, Callable with a nested Concatenate can be substituted, and we currently implement that by using Concatenate's substitution behavior as proxy. But again, the meaning isn't clear to me.
I also noticed this strange part in PEP 612 about user-defined generic classes:
"`Generic[P]` makes a class generic on `parameters_expressions` (when P is a ParamSpec)":
...
class X(Generic[T, P]):
f: Callable[P, int]
x: T
def f(x: X[int, Concatenate[int, P_2]]) -> str: ... # Accepted (KJ: What?)
...
The grammar for `parameters_expression` is:
parameters_expression ::=
| "..."
| "[" [ type_expression ("," type_expression)* ] "]"
| parameter_specification_variable
| concatenate "["
type_expression ("," type_expression)* ","
parameter_specification_variable
"]"
I'm very confused. Does this mean Concatenate is valid when substituting user generics? Maybe I should ask the PEP authors?
My general sense when I implemented the PEP was that it was intended primarily for static type checking only. IMO, runtime correctness wasn't its concern.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44791>
_______________________________________
More information about the Python-bugs-list
mailing list