<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Nov 25, 2017 at 1:14 AM, Stephan Hoyer <span dir="ltr"><<a href="mailto:shoyer@gmail.com" target="_blank">shoyer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">There's been growing interest in supporting PEP-484 style type annotations in NumPy: <a href="https://github.com/numpy/numpy/issues/7370" target="_blank">https://github.com/numpy/<wbr>numpy/issues/7370</a><div><div><br></div><div>This would allow NumPy users to add type-annotations to their code that uses NumPy, which they could check with mypy, pycharm or pytype. For example:</div><div><br></div><div>def f(x: np.ndarray) -> np.ndarray:</div><div>    """Identity function on a NumPy array."""</div><div>    return x</div><div><br></div><div>Eventually, we could include data types and potentially array shapes as part of the type. This gets quite a bit more complicated, and to do in a really satisfying way would require new features in Python's typing system. To help guide discussion, I wrote a doc describing use-cases and needs for typing array shapes in more detail: <a href="https://docs.google.com/document/d/1vpMse4c6DrWH5rq2tQSx3qwP_m_0lyn-Ij4WHqQqRHY" target="_blank">https://docs.google.com/<wbr>document/d/<wbr>1vpMse4c6DrWH5rq2tQSx3qwP_m_<wbr>0lyn-Ij4WHqQqRHY</a></div><div><br></div><div>Nathaniel Smith and I recently met with group in San Francisco interested in this topic, including several mypy/typeshed developers (Jelle Zijlstra and Ethan Smith). We discussed and came up with a plan for moving forward:</div></div><div>1. Release basic type stubs for numpy.ndarray without dtypes or shapes, as separate "numpy_stubs" package on PyPI per PEP 561. This will let us iterate rapidly on (experimental) type annotations without coupling to NumPy's release cycle.</div><div>2. Add support for dtypes in ndarray type-annotations. This might be as simple as writing np.ndarray[np.float64], but will need a decision about appropriate syntax for shape typing to ensure that this is forwards compatible with typing shapes. Note: this will likely require minor changes to NumPy itself, e.g., to add __class_getitem__ per PEP 560.</div><div>3. Add support for shapes in ndarray type-annotations, and define a broader standard for typing array shapes. This will require collaboration with type-checker developers on the required typing features (for details, see my doc above). Eventually, this may entail writing a PEP.</div><div><br></div></div></blockquote><div><br></div><div>Can you make a case for the usefulness numpy annotations? What benefits to you want to achieve and how will annotation aid in getting there.</div><div><br></div><div>Chuck</div></div></div></div>