TYP: np.[a]round improved shape-typing - #32241
Merged
Merged
Conversation
|
Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code: colour (https://github.com/colour-science/colour)
+ colour/io/image.py:350: error: Incompatible return value type (got "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]", expected "ndarray[tuple[Any, ...], dtype[signedinteger[_8Bit] | signedinteger[_16Bit] | signedinteger[_32Bit] | signedinteger[_64Bit] | unsignedinteger[_8Bit] | unsignedinteger[_16Bit] | unsignedinteger[_32Bit] | unsignedinteger[_64Bit] | floating[_16Bit] | floating[_32Bit] | float64]]") [return-value]
- colour/colorimetry/spectrum.py:418: error: Argument 1 to "around" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"; expected "complex | number[Any, Any] | numpy.bool[builtins.bool] | object_" [arg-type]
+ colour/colorimetry/spectrum.py:418: error: Argument 1 to "around" has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"; expected "complex" [arg-type]
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/type_blocks.py:1633: error: Unused "type: ignore" comment [unused-ignore]
optuna (https://github.com/optuna/optuna)
./optuna/study/_multi_objective.py:182: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
|
Member
Author
|
RE: the new mypy_primer errors:
|
Member
|
Thanks Joren. |
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.
np.around(a.k.a.np.round) is now also shape-type-aware in case of (nested) sequences for the 1d/2d cases, and no longer erases shape-types ofboolarrays. This also resolves the incompatible overlapping overloads, towards #27032.Fully written by me, audited as kinda-high-value shape-typing improvement by AI (see https://gist.github.com/jorenham/36c78602a7ca866ddb2a917de48ccdd0).