[Numpy-discussion] Type annotations for NumPy

Kirill Balunov kirillbalunov at gmail.com
Sun Nov 26 06:00:53 EST 2017


2017-11-26 4:31 GMT+03:00 Juan Nunez-Iglesias <jni.soma at gmail.com>:

> On 26 Nov 2017, 12:27 PM +1100, Nathaniel Smith <njs at pobox.com>, wrote:
> It turns out that the PEP 484 type system is *mostly* not useful for
> this. They're really designed for checking consistency across a large
> code-base, not for enabling compiler speedups. For example, if you
> annotate something as an int, that means "this object is a subclass of
> int". This is enough to let mypy catch your mistake if you
> accidentally pass in a float instead, but it's not enough to tell you
> anything at all about the object's behavior -- you could make a wacky
> int subclass that acts like a string or something.
I have subscribed to many lists, although I am not an active participant in
them. Nevertheless this topic of using the type annotation in their
projects was discussed several times on all Cython-like channels (and it
becomes much more acute now days). "Misconceptions" arise both for ordinary
users and developers, but I have never seen anyone to write clearly why the
application of type annotation in Cython (and similar projects) is
impossible or not reasonable. Maybe someone close to the topic has the time
and energy to sum up and write a brief summary of how to perceive them and
why they should be viewed "orthogonal"?

Maybe I'm looking too superficially at this topic. But both Mypy and Cython
perform type checking. From the Cython point of view I do not see any
pitfalls, type checking and type conversions are what Cython is doing right
now during compilation (and looks at types as strictly as necessary).
>From Mypy's point of view, it's possible that it can delegate all this
stuff, using a certain option, on a project's related type checker (which
can be much stricter in its assumptions)

With kind regards, -gdg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20171126/2eb6ac13/attachment-0001.html>

More information about the NumPy-Discussion mailing list