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 initial annotations to np.core.multiarray #19060

Merged
merged 7 commits into from
Jun 10, 2021

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented May 21, 2021

This PR adds initial annotations to np.core.multiarray.

DType-support is still far from comprehensive, but at the very least all types that can be parametrized w.r.t. np.generic are now automatically recognized.

Examples

from typing import TYPE_CHECKING
import numpy as np

AR_f8 = np.array([1], dtype=np.float64)
AR_f8_copy = np.array(AR_f8)
AR_f8_0d = np.array(np.float64())

if TYPE_CHECKING:
    # Revealed local types are:
    #     AR_f8: numpy.ndarray[Any, numpy.dtype[numpy.floating*[numpy.typing._64Bit*]]]
    #     AR_f8_0d: numpy.ndarray[Any, numpy.dtype[numpy.floating*[numpy.typing._64Bit*]]]
    #     AR_f8_copy: numpy.ndarray[Any, numpy.dtype[numpy.floating*[numpy.typing._64Bit*]]]
    reveal_locals()


__all__: List[str]

@overload
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a common overload pattern:

  1. Array-likes that can be parametrized w.r.t. generic
  2. All other array-likes
  3. DType-likes that can be parametrized w.r.t. generic
  4. All other DType-likes

@BvB93
Copy link
Member Author

BvB93 commented May 31, 2021

Any comments on this PR?

@charris charris merged commit 8cb1273 into numpy:main Jun 10, 2021
@charris
Copy link
Member

charris commented Jun 10, 2021

Thanks Bas.

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

2 participants