On Apr 7, 2021, at 12:59, Guido van Rossum <gu...@python.org> wrote:
> 
> Note that in TypeScript this also doesn't look like a boolean -- it uses a 
> unique syntax that has to be learned:
> 
> function isCustomer(partner: any): partner is Customer {
>     . . .
> }
> 
> Arguably the TS syntax is more easily intuited without looking it up, but TS 
> has a certain freedom in its syntactic design that we don't have for Python: 
> new *syntax* has to be added to the Python parser and can't be backported, 
> whereas new *types* (like `TypeGuard[T]`) can easily be backported via 
> typing_extensions.py.

Thanks Guido.  Yes, we totally understand.  I agree that this TS example is 
easier to reason about (at least for me), and that Python is limited in what 
syntax it can allow there.

This is something the SC has been musing about, but as it’s not a fully formed 
idea, I’m a little hesitant to bring it up.  That said, it’s somewhat relevant: 
We wonder if it may be time to in a sense separate the typing syntax from 
Python’s regular syntax.  TypeGuards are a case where if typing had more 
flexibility to adopt syntax that wasn’t strictly legal “normal” Python, maybe 
something more intuitive could have been proposed.  I wonder if the typing-sig 
has discussed this possibility (in the future, of course)?

> We have really tried, but we did not come up with anything better than the 
> current PEP.

Neither did the SC, thus the acceptance! :D  I have no doubt typing-sig really 
tried hard!

> FWIW you might be interested in Annotated (PEP 593), which can be used to 
> indicate various attributes of a type annotation. Before you suggest that we 
> adopt that instead of PEP 647, we considered that, and the consensus is that 
> that's not what Annotated is for (it's intended for conveying information to 
> tools *other* than the type checker, for example schema checkers etc.).

Agreed.  It’s interesting that PEP 593 proposes a different approach to 
enriching the typing system.  Typing itself is becoming a little ecosystem of 
its own, and given that many Python users are still not fully embracing typing, 
maybe continuing to tie the typing syntax to Python syntax is starting to 
strain.

Cheers,
-Barry

Attachment: signature.asc
Description: Message signed with OpenPGP

_______________________________________________
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/YMNPYKWVM537V7A6LJXG5R3GUCOTBYTL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to