
The goal for Annotated is to be very flexible. We intended it to be an "escape hatch" that allows clients to express things that type-checkers might not understand. I'm all for enabling it in as many places as possible. Let me know if you want me to work on a diff and/or a revision of PEP-593 to clarify any of this. Sorry I took so long to respond, Till T On Mon, 21 Feb 2022 at 12:27, Serhiy Storchaka <storchaka@gmail.com> wrote:
08.02.22 22:39, Gregory Beauregard via Typing-sig пише:
Recently, we fixed Annotated so that it is allowed to wrap Final and ClassVar[1]. Since then I have found a number of other places where Annotated cannot wrap typeforms at runtime. In an issue addressing that ParamSpec P.args and P.kwargs cannot be wrapped at runtime [2], it was brought up that one might not consider these types and thus they might contravene the PEP 593 (Annotated)[3] statement "The first argument to Annotated must be a valid type" and thus we should discuss it publicly.
It is my position that the PEP never intended to disallow using Annotated on top-level typeforms (like P.args and P.kwargs), and that moreover the intention either always was or should be that if an Annotated contains something that would be a valid typeform in that location, it's a valid place to use Annotated. If we look back on the typing issue [4] that discussed adding Annotated, the requirement is worded that the first Annotated argument must be a "valid `typing` type" as opposed to a type in some stricter understanding of the term. A stronger argument I think is in the impetus of the PEP itself: the PEP is intended to allow typing and non-typing users of annotation space in Python to coexist. If the PEP intended to completely disallow Annotated to be used in certain annotation spots, the PEP isn't accomplishing one of its primary stated intentions.
Is there agreement that Annotated should be allowed in these locations?
And if allow Annotated to wrap ParamSpecArgs and ParamSpecKwargs, should we allow it to wrap a parameters expression? For example:
Callable[Annotated[P, "annotated"], int] Callable[Annotated[Concatenate[str, P], "annotated"], int] Callable[Annotated[[str, float], "annotated"], int] Callable[Annotated[..., "annotated"], int]
_______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: till.varoquaux@gmail.com