[Cython] Py3 annotation syntax for static typing

Stefan Behnel stefan_ml at behnel.de
Thu Jul 11 19:52:38 CEST 2013


[CC-ing cython-dev]

Hi Jukka,

I stumbled over your blog post at

http://mypy-lang.blogspot.de/2013/07/mypy-switches-to-python-compatible.html

It says that you are starting to adopt the Py3 function annotation syntax
for mypy. I think we should try to keep that in sync for both mypy and
Cython. It would be bad to have two ways to do it.

When we discussed this for Cython (see the trac ticket [1] and Wiki entry
[2] below), also on the mailing list (back in 2008 I guess), the main
problem was that it's not immediately clear what should be considered type
annotations by the compiler and what's arbitrary "other stuff" that users
put into declarations. There's also no obvious way to allow for multiple
independent annotations. Should they be in a tuple? In a dict? What would
be dict key be? How can we prevent collisions and conflicts when multiple
tools base their features on annotations?

It's mainly a namespace problem. The annotation namespace is essentially
flat, and I think that only practical usage can eventually establish
suitable conventions.

I'd like to discuss this, maybe we can come up with a suitable Best
Practice. What's your opinion on the issue so far?

There's also our current Pure Python syntax mode for everything that cannot
be expressed with function annotations:

http://docs.cython.org/src/tutorial/pure.html

I would guess that mypy will eventually need something similar.

Stefan


[1] http://trac.cython.org/cython_trac/ticket/752

[2] http://wiki.cython.org/enhancements/pure


More information about the cython-devel mailing list