Repository navigation
Include array shape in generated annotations - #132
Merged
Merged
Conversation
This bundles a few things that I should have probably committed separately while iterating on them: 1. Shape information in doctypes is now translated into annotations. This even goes for shapes with optional dimensions – which use expansion like in the plugin example to create a union of arrays – one for each supported dimensionality. Shapes with "..." are treated as unbounded dimensionality and translated to `tuple[Any, ...]` like NumPy v2.5 suggests [1]. Empty shapes are supported too. 2. Dtype unions are now also expanded into a union of arrays each with one of the dtypes. This is because I'm not sure if `np.dtype` actually supports unions. I can't find examples of that in NumPy's repo. For now, expansion should be on the safe side. 3. Shape and dtype are now stripped from *ArrayLikes* which don't support them as their are a union that can't be subscribed [1]. This means, *ArrayLikes* are a really generic broad type. Will address scientific-python#125. Some refactoring, and especially new stuff like `expand_expression`, `Expr.{find_all|try_find_one|find_one}` enable all this. [1] https://numpy.org/doc/stable/reference/typing.html#api
lagru
marked this pull request as ready for review
November 6, 2026 21:58
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.
This bundles a few things that I should have probably committed separately while iterating on them:
Closes Include shape of NumPy array #76. Shape information in doctypes is now translated into annotations. This even goes for shapes with optional dimensions – which use expansion like in the plugin example to create a union of arrays – one for each supported dimensionality. Shapes with "..." are treated as unbounded dimensionality and translated to
tuple[Any, ...]like NumPy v2.5 suggests. Empty shapes are supported too.Dtype unions are now also expanded into a union of arrays each with one of the dtypes. This is because I'm not sure if
np.dtypeactually supports unions. I can't find examples of that in NumPy's repo. For now, expansion should be on the safe side.Closes ArrayLike limitations #125. Shape and dtype are now stripped from ArrayLikes which don't support them as their are a union that can't be subscribed. This means, ArrayLikes are a really generic broad type.
Cleans up some issues with the grammar: the literal and subscriptions rules have some necessary overlap. The subscription rule should now win unless the expression contains an actual literal type.
Also some refactoring, and especially new stuff like
expand_expression,Expr.{find_all|try_find_one|find_one}enable all this.Release note
For maintainers and optionally contributors, please refer to changelist's README on how to document this PR for the release notes.