[Numpy-discussion] Type annotations for NumPy
njs at pobox.com
Sat Nov 25 20:24:55 EST 2017
On Sat, Nov 25, 2017 at 3:09 PM, Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
> This is a complete outsider’s perspective but
> (a) it would be good if NumPy type annotations could include an “array_like”
> type that allows lists, tuples, etc.
I'm sure this will exist.
> (b) I’ve always thought (since PEP561) that it would be cool for type
> annotations to replace compiler type annotations for e.g. Cython and Numba.
> Is this in the realm of possibility for the future?
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.
Probably there are some benefits that compilers can get from PEP 484
annotations, but you should think of them as largely an orthogonal
Nathaniel J. Smith -- https://vorpus.org
More information about the NumPy-Discussion