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

Steven D'Aprano steve at pearwood.info
Sat Aug 16 19:15:09 CEST 2014


On Sat, Aug 16, 2014 at 03:00:15PM +0200, Dave Halter wrote:

> I think a resulting PEP of this discussion should contain a deprecation
> note for all usages other than type checking in Python 3.5.

Can you explain your reasoning for this?

I understand that unless they are deliberately built to cooperate, two 
users of annotations are likely to interfere with each other. The jedi 
tool wants annotations to be type information; the sith tool wants 
annotations to be X-Face pictures of kittens. They can't both get what 
they want.

You are asking for alternative uses of annotations, such as pictures of 
kittens, to be deprecated. But it seems to me that all you really need 
is some standard way for jedi to look at the function and cheaply see 
that it shouldn't try interpreting the annotations as types. (And, 
mutatis mutandis, the same applies to sith.) That allows jedi and sith 
to co-exist, although we can't use both on the same function at the same 
time.

I think it is fair for Python to standardise on type checking as the 
default semantics of annotations, but I would like to see a way to 
opt-out and still use annotations for other purposes.


> The current
> ambiguous nature of annotations is the fact why no static analysis tool
> ever checked them.

mypy does. Hence this proposal.

So does PyCharm:

http://www.jetbrains.com/pycharm/webhelp/type-hinting-in-pycharm.html

On the other hand, in this thread we've heard from two others who use 
function annotations for purposes other than types. So it seems to me 
that usage of annotations is split right down the middle between typing 
and non-typing.


-- 
Steven


More information about the Python-ideas mailing list