GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-44796: Unify TypeVar and ParamSpec substitution by serhiy-storchaka · Pull Request #31143 · python/cpython Conversation
|
| f"ParamSpec, or Concatenate. Got {t_args}") | ||
| return super().__new__(cls, origin, args) | ||
|
|
||
| @property |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think we have to keep __parameters__, it's de facto a public API by now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is inherited from GenericAlias now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if isinstance(arg, _SpecialForm) or arg in (Generic, Protocol): | ||
| raise TypeError(f"Plain {arg} is not valid as type argument") | ||
| if isinstance(arg, (type, TypeVar, ForwardRef, types.UnionType, ParamSpec)): | ||
| if isinstance(arg, (type, TypeVar, ForwardRef, types.UnionType)): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will this affect putting ParamSpec inside Annotated? Looks like we don't have tests for that yet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I looked into this.
This check is needed in order to allow instances of ParamSpec (i.e. P in P = ParamSpec("P")) to pass typing._type_check because callable(P) is False. This can show up for instance like Callable[Annotated[P, ""], T]. This line's change would regress the behavior to a runtime error.
n.b. this is moot if #31151 gets merged since this line is removed entirely
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Callable[Annotated[P, ""], T] does not conform the PEP 612 specification.
callable ::= Callable "[" parameters_expression, type_expression "]"
parameters_expression ::=
| "..."
| "[" [ type_expression ("," type_expression)* ] "]"
| parameter_specification_variable
| concatenate "["
type_expression ("," type_expression)* ","
parameter_specification_variable
"]"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced it was the intent of the spec here to disallow Annotated, but you can also reach this code here:
from typing import Callable, TypeVar, ParamSpec, get_type_hints T = TypeVar("T") P = ParamSpec("P") def add_logging(f: Callable["P", T]): pass get_type_hints(add_logging)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Well, I re-added ParamSpec. Now some errors will not be caught at runtime. We will return to this in future.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| and _is_unpacked_typevartuple(old_arg)): | ||
| if _is_unpacked_typevartuple(old_arg): | ||
| original_typevartuple = old_arg.__parameters__[0] | ||
| new_arg = new_arg_by_param[original_typevartuple] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This code is not covered by tests.
It perhaps could be simplified too, but since it is not covered by tests I left it as is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It now includes PEP 646 changes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Did anyone review this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, it was not reviewed after the last changes. But I addressed previous review comments. Is there something wrong with this code? I merged this PR after short delay because it allows the C code for TypeVarTuple substitution (#31828) to be of reasonable complexity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.