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

Andrey Vlasovskikh andrey.vlasovskikh at gmail.com
Sun Aug 17 12:36:07 CEST 2014


2014-08-17, 9:03, Guido van Rossum <guido at python.org> wrote:

> My first concern is that these expressions are only unambiguous in the context of function annotations. I want to promote the use of type aliases, and I think in general a type alias should behave similarly to an ABC. In particular, I think that any object used to represent a type in an annotation should itself be a type object (though you may not be able to instantiate it), and e.g. [int] doesn't satisfy that requirement. Without this, it would be difficult to implement isinstance() and issubclass() for type aliases -- and while we could special-case lists, sets and dicts, using a tuple *already* has a meaning!

Having type annotations as type objects sounds good. The fact that we can use isinstance() and issubclass() for all type annotations would provide some level of compatibility between static type checking and potential dynamic type checking: if "x: <type-expr>" then "isinstance(x, <type-expr>)".

Note, that not all type annotations of mypy are currently type objects. Probably this should be fixed. 

-- 
Andrey Vlasovskikh

Web: http://pirx.ru/



More information about the Python-ideas mailing list