[Python-ideas] Optional static typing -- the crossroads
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Aug 16 02:10:54 CEST 2014
Sunjay Varma wrote:
> dict<str, int> seems to tell me more explicitly that I'm dealing with a
> declaration of an expected type.
In addition to my earlier objections to angle brackets,
there would be a big problem with parsing this notation
in Python.
In languages that use syntax like this, there is a clear
division between type descriptions and expressions --
they belong to completely separate areas of the grammar.
However, we need to be able to parse our type descriptions
as expressions, because they *are* expressions, just like
any other.
Now consider:
dict<str, int>
^^^^^^^^^^^^^
Everything up to the final '>' is a valid Python expression,
equivalent to
((dict < str), int)
so the parser would have to be capable of completely changing
its mind about how to interpret all of that when it saw the
'>'. I'm fairly sure that Python's mostly-LL parser can't do
that.
--
Greg
More information about the Python-ideas
mailing list