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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m trying to get my head around why the third option below still needs the union. Are there inputs other than
X: float, alpha: float
that would return a tuple? Or does the checker check thefloat, float
combination against both because floats are array-like and the checker doesn’t stop after finding the precise match? Or something else?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArrayLike
is a fair bit broader than I would actually like in many cases. Numpy (understandably) does not provide all of its building blocks as public apis, though, so narrowing it would essentially mean reimplementing or vendoring a lot of the machinery. But I suspect there are things that do qualify under arraylike that may not qualify as Sequence (particularly things that provide a__array__
method, though probably still inadvisable to make such a thing that isn't considered a sequence)Mypy does not like when multiple signatures are given that are incompatible, though and float is included in arraylike, so it's output must also be in the return type.
One option would be to make the fallback
Any
so that users won't have to deal with a union return type but mypy also doesn't complain. It's a bit of a cop out answer, but sometimes best for situations where the return type is known but cannot be differentiated by input types (in this case because we want the catch all arraylike to be sure we didn't miss anything)The other aspect I didn't fully think about was if other scalars could be passed, though pretty sure it essentially is floats (and int I guess, but type checkers accept int when typed as float)
TLDR it's a conservative catch all that probably isn't going to be selected in most use cases, but needs to be consistent with the other signature options