Repository navigation
TYP: Semi-transparent numpy.shape shape-type annotations. - #27210
Merged
Merged
Conversation
numpy.shape shape-type annotations.numpy.shape shape-type annotations.
Member
Author
jorenham
force-pushed
the
typing/numpy.shape
branch
from
August 15, 2024 09:44
7834733 to
c5d52f3
Compare
Member
|
Thanks @jorenham . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before,
numpy.shape()always returnedtuple[int, ...].This changes
numpy.shapeso return:tuple[()](the empty "0-d" tuple) for scalar-likestuple[int]for scalar sequences,memoryviews andbytearraystuple[int, int]for sequences of scalar sequences, e.g.[[1, 0], [0, 1]]tuple[int, ...]forndarray[Any, Any](so notAny, see TYP: Stop usingAnyas shape-type default #27211 for details)ShapeType: tuple[int, ...]for objects with ashape: ShapeTypeproperty, which includesdtypeandndarray, unlessShapeTypeis bound toAny(npt.NDArraycurrently does this). This doesn't work on mypy, probably due to one of its (many) bugs. I wasn't able to find a workaround for this unfortunately (dimension-specific overloads aren't even possible, as that would also matchNDArray).tuple[int, ...]for any other array-likes