<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">This is a complete outsider’s perspective but
<div><br /></div>
<div>(a) it would be good if NumPy type annotations could include an “array_like” type that allows lists, tuples, etc.</div>
<div>(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?</div>
<div><br /></div>
<div>Juan.</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On 26 Nov 2017, 3:54 AM +1100, Charles R Harris <charlesr.harris@gmail.com>, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<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: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<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>
_______________________________________________<br />
NumPy-Discussion mailing list<br />
NumPy-Discussion@python.org<br />
https://mail.python.org/mailman/listinfo/numpy-discussion<br /></blockquote>
<div></div>
</div>
</body>
</html>