<div dir="ltr"><div dir="ltr">>
Putting<br>> aside ndarray, as more challenging, even annotations for numpy functions<br>> and method parameters with built-in types would help, as a start.<div><br></div><div>This is a good idea in principle, but one thing concerns me.</div><div><br></div><div>If we add type annotations to numpy, does it become an error to have numpy-stubs installed?</div><div>That is, is this an all-or-nothing thing where as soon as we start, numpy-stubs becomes unusable?</div><div><br></div><div>Eric</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 24 Mar 2020 at 17:28, Roman Yurchak <<a href="mailto:rth.yurchak@gmail.com">rth.yurchak@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks for re-starting this discussion, Stephan! I think there is <br>
definitely significant interest in this topic: <br>
<a href="https://github.com/numpy/numpy/issues/7370" rel="noreferrer" target="_blank">https://github.com/numpy/numpy/issues/7370</a> is the issue with the largest <br>
number of user likes in the issue tracker (FWIW).<br>
<br>
Having them in numpy, as opposed to a separate numpy-stubs repository <br>
would indeed be ideal from a user perspective. When looking into it in <br>
the past, I was never sure how well in sync numpy-stubs was. Putting <br>
aside ndarray, as more challenging, even annotations for numpy functions <br>
and method parameters with built-in types would help, as a start.<br>
<br>
To add to the previously listed projects that would benefit from this, <br>
we are currently considering to start using some (minimal) type <br>
annotations in scikit-learn.<br>
<br>
-- <br>
Roman Yurchak<br>
<br>
On 24/03/2020 18:00, Stephan Hoyer wrote:<br>
> When we started numpy-stubs [1] a few years ago, putting type <br>
> annotations in NumPy itself seemed premature. We still supported Python <br>
> 2, which meant that we would need to use awkward comments for type <br>
> annotations.<br>
> <br>
> Over the past few years, using type annotations has become increasingly <br>
> popular, even in the scientific Python stack. For example, off-hand I <br>
> know that at least SciPy, pandas and xarray have at least part of their <br>
> APIs type annotated. Even without annotations for shapes or dtypes, it <br>
> would be valuable to have near complete annotations for NumPy, the <br>
> project at the bottom of the scientific stack.<br>
> <br>
> Unfortunately, numpy-stubs never really took off. I can think of a few <br>
> reasons for that:<br>
> 1. Missing high level guidance on how to write type annotations, <br>
> particularly for how (or if) to annotate particularly dynamic parts of <br>
> NumPy (e.g., consider __array_function__), and whether we should <br>
> prioritize strictness or faithfulness [2].<br>
> 2. We didn't have a good experience for new contributors. Due to the <br>
> relatively low level of interest in the project, when a contributor <br>
> would occasionally drop in, I often didn't even notice their PR for a <br>
> few weeks.<br>
> 3. Developing type annotations separately from the main codebase makes <br>
> them a little harder to keep in sync. This means that type annotations <br>
> couldn't serve their typical purpose of self-documenting code. Part of <br>
> this may be necessary for NumPy (due to our use of C extensions), but <br>
> large parts of NumPy's user facing APIs are written in Python. We no <br>
> longer support Python 2, so at least we no longer need to worry about <br>
> putting annotations in comments.<br>
> <br>
> We eventually could probably use a formal NEP (or several) on how we <br>
> want to use type annotations in NumPy, but I think a good first step <br>
> would be to think about how to start moving the annotations from <br>
> numpy-stubs into numpy proper.<br>
> <br>
> Any thoughts? Anyone interested in taking the lead on this?<br>
> <br>
> Cheers,<br>
> Stephan<br>
> <br>
> [1] <a href="https://github.com/numpy/numpy-stubs" rel="noreferrer" target="_blank">https://github.com/numpy/numpy-stubs</a><br>
> [2] <a href="https://github.com/numpy/numpy-stubs/issues/12" rel="noreferrer" target="_blank">https://github.com/numpy/numpy-stubs/issues/12</a><br>
> <br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
> <br>
<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div></div>