
On Apr 7, 2021, at 12:59, Guido van Rossum <guido@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