On Fri, Oct 8, 2021 at 3:36 PM Barry Warsaw <barry@python.org> wrote:
On Oct 8, 2021, at 13:02, Sergei Lebedev <sergei.a.lebedev@gmail.com> wrote:
>
> I agree that type annotation syntax should be consistent with the rest of the language, but I'm curious why it has to be "standard Python syntax"? Could you elaborate a bit more on the reasoning behind that constraint?


Hi Sergei.  I don’t mean anything more than just that there should be a single syntax for all of Python. I was just trying to describe “the bits of Python that aren’t type annotations”.

I interpret this as follows:

- Whatever we choose (say, "(int, int) -> int") should be allowed where expressions are allowed, so that e.g.

    foo = (int, int) -> int

assigns *something* at runtime -- it shouldn't be a syntax error and it shouldn't raise an exception.

My preference would be for it to return something that's introspectable, i.e. an object lets one recover the original info. That's what we did when we introduced "A | B" as union syntax for types. (It's slightly different because that was already valid syntax, but the principle that it must return something introspectable is the same.) Union objects have an `__args__` attribute that gives the underlying types, and a `__parameters__` attribute giving any type variables.

Note that the implementation of this introspectable type should ultimately be in C.

--
--Guido van Rossum (python.org/~guido)