[Python-ideas] Optional static typing -- the crossroads

Petr Viktorin encukou at gmail.com
Fri Aug 15 20:56:22 CEST 2014


On Fri, Aug 15, 2014 at 8:43 PM, Sunjay Varma <varma.sunjay at gmail.com> wrote:
> Hi all,
> Has the syntax for specifying type been fully decided on already?
>
> Using brackets may confuse new Python programmers. Since specifying type in
> Python is fairly new anyway, what do you all think of introducing angle
> brackets into Python instead? Other languages use angle brackets to specify
> types. It provides a good separation between type specification and list
> indexing.
>
> I'm also worried that using square brackets will cause confusion as that
> notation is generally associated with array declarations in other languages.
> Even in Python, MyClass[int] may be confused with getting a key called int
> from some MyClass.
>
> dict<str, int> seems to tell me more explicitly that I'm dealing with a
> declaration of an expected type. dict[str, int] looks very much like I'm
> getting an item (str, int) from some class.
>
> The angle bracket (or any other suggestions you have in mind) provides a
> more concrete separation between when we are performing item indexing and
> when we're specifying a type to validate.

Square brackets have the advantage of being valid Python now, so typed
code would be backwards compatible.

If the syntax was to change, what about a new operator?
    def sum(seq: Iterable of Number, start: Number):

    def print_grades(p: Mapping of (Student, Grade)):

Just an idea.


More information about the Python-ideas mailing list