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

Ryan Hiebert ryan at ryanhiebert.com
Fri Aug 15 20:56:17 CEST 2014


> On Aug 15, 2014, at 1:43 PM, Sunjay Varma <varma.sunjay at gmail.com> wrote:
> 
> 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.

Angle brackets already have meaning in Python, as comparison operators. The current surrounding operators ([], (), {}) require a matched pair in all cases. Breaking that rule would be confusing, though I know there are languages that do that.
> 
> 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.
> 
Getting an item from a class has no meaning for any classes that I’ve ever used, and I haven’t come up with any hypothetical one that would want to do that.

I think that the parallel between item access and item declaration is a great argument in favor of using the dict[str, int] (or perhaps dict[str: int]) syntax as a type declaration.

Ryan


More information about the Python-ideas mailing list