On Fri, Oct 8, 2021 at 3:36 PM Barry Warsaw <ba...@python.org> wrote:

> On Oct 8, 2021, at 13:02, Sergei Lebedev <sergei.a.lebe...@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)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/5X2XE52DDSCOFYVDO2IMBUKBQPU4HQUD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to