Skip to content
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

ENH: Add annotations for five array construction functions #17326

Merged
merged 9 commits into from
Oct 1, 2020

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Sep 16, 2020

This pull request adds annotations to the five array construction functions in np.core._asarray:

  • asarray
  • asanyarray
  • ascontiguousarray
  • asfortranarray
  • require

) -> ndarray: ...
@overload
def asanyarray(
a: _ArrayType,
Copy link
Member Author

@BvB93 BvB93 Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def(a: _ArrayType, ...) -> _ArrayType implies that both the array (sub-)class, dtype and shape are identical for the input and output.

Without higher-kindred typevars (python/typing#548) we, unfortunately, can not describe a situation were an ndarray subclass is returned with a dtype that is different from the initial input (hence the dtype: None in this overload).

numpy/core/_asarray.pyi Outdated Show resolved Hide resolved
@BvB93
Copy link
Member Author

BvB93 commented Sep 17, 2020

Rebased to get rid of a merge conflict.

@BvB93
Copy link
Member Author

BvB93 commented Sep 23, 2020

71def2c implements an alternative approach for ensuring that externally-defined stubs are
picked up in the main __init__.pyi file. Using from x import y as y is more compact than
specifying them in __all__ and, more importantly, it is less prone to merge conflicts.

@BvB93
Copy link
Member Author

BvB93 commented Oct 1, 2020

be77442 removes the placeholder annotations (see #17406) for the newly annotated functions introduced in this PR.

Secondly, if there are no further comments then I feel this can get merged.

@charris charris merged commit e695dd0 into numpy:master Oct 1, 2020
@charris
Copy link
Member

charris commented Oct 1, 2020

Thanks @BvB93 .

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.

None yet

3 participants