8000 ENH: Add annotations for remaining `ndarray` / `generic` non-magic methods by BvB93 · Pull Request #17372 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add annotations for remaining ndarray / generic non-magic methods #17372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 5, 2020

Conversation

BvB93
Copy link
Member
@BvB93 BvB93 commented Sep 23, 2020

This pull request adds annotations for all remaining ndarray / generic non-magic methods.

Fortunately, most of these methods were already typed in their function-based counterpart from
np.core.fromnumeric, so they could be copied over with minor alterations.

A few notes and observations:

  • The annotations are mostly geared towards ndarray. While they're not necessarily incorrect for
    generic, the signatures are generally speaking a bit too broad. Something to refine in a follow up.

  • The overload pattern of ndarray.all() is a very common one here:

    • out is None, axis is None and keepdims is False -> a generic is returned.
    • out is None and (axis is not None or keepdims is True) -> a generic or ndarray is returned.
    • out is not None -> out is returned. One of the few cases where we can safelly use a typevar.
  • A few annotations, that were recently moved to np.core.fromnumeric (MAINT: Move the fromnumeric annotations to their own stub file #17309), have been
    moved back to the main __init__.pyi file, as they were needed for the newly annotated methods.

  • A number of methods, that are either just plain unavailable to generic or require a >=1D array, have
    been moved from _ArrayOrScalarCommon to ndarray.

@BvB93
Copy link
Member Author
BvB93 commented Oct 5, 2020

Any comments?

@charris charris merged commit 9ebd2bf into numpy:master Oct 5, 2020
@charris
Copy link
Member
charris commented Oct 5, 2020

Thanks @BvB93 . No comments, but 12 days old, so in it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0