Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: Shape-typed array constructors: numpy.{empty,zeros,ones,full} #27171

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 2 commits into from
Sep 2, 2024

Conversation

jorenham
Copy link
Member

Added overloads to the (direct) array constructor functions in the stubs. These "bind" the type of the passed shape argument to the shape-type parameter of the numpy.ndarray. Note that this is only possible when the shape is passed as shape: int or shape: tuple[int, int], since e.g. the list type contains no information about its length (i.e. the number of dimensions).

This affects the type-signatures of:

  • numpy.empty (numpy._core.multiarray.empty)
  • numpy.zeros (numpy._core.multiarray.zeros)
  • numpy.ones (numpy._core.numeric.ones)
  • numpy.full (numpy._core.numeric.full)

implementation notes:


This should be backwards-compatible, because the ndarray shape-type parameter is covariant, see #26081.

@charris
Copy link
Member

charris commented Aug 30, 2024

Needs rebase.

@jorenham jorenham force-pushed the typing/shaped-array-constructors branch from 9211e27 to 7f85de4 Compare September 2, 2024 10:44
@charris
Copy link
Member

charris commented Sep 2, 2024

Needs another rebase :)

@jorenham jorenham force-pushed the typing/shaped-array-constructors branch from 7f85de4 to f3dd2e1 Compare September 2, 2024 14:09
@charris charris merged commit f1d11b3 into numpy:main Sep 2, 2024
66 checks passed
@charris
Copy link
Member

charris commented Sep 2, 2024

Thanks @jorenham .

@jorenham jorenham deleted the typing/shaped-array-constructors branch September 2, 2024 15:39
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