Add more types for Random#470
Merged
Merged
Conversation
soutaro
reviewed
Nov 11, 2020
| # | ||
| def rand: () -> Float | ||
| | (Integer | ::Range[Integer] max) -> Integer | ||
| | (Integer | ::Range[Integer] | Numeric max) -> Integer |
Member
There was a problem hiding this comment.
Seems like having Numeric here will return Integer for any numbers including Float.
Moving this line after next line would give better type.
soutaro
reviewed
Nov 11, 2020
| | (Integer | ::Range[Integer] max) -> Integer | ||
| | (Integer | ::Range[Integer] | Numeric max) -> Integer | ||
| | (Float | ::Range[Float] max) -> Float | ||
| | (::Range[Numeric]) -> Numeric |
Member
There was a problem hiding this comment.
Yeah, the type we want would be [T <: Numeric] (Range[T]) -> T, but RBS currently doesn't allow writing it.
I think there are two options. [T] (Range[T]) -> T or (Range[Numeric]) -> Numeric. The first option would make sense in my opinion, because testing the code will uncover the problem anyway.
soutaro
added a commit
that referenced
this pull request
Nov 24, 2022
Add more types for Random (fix conflict #470)
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 is my first time writing RBS so I am not sure it is right, especially the tests.
I am not sure how to fully describe
randbecause it can return whatever type you give it, for example:In other words,
rand: (Range[SomeType]) -> SomeTypebut I don't know how to write that in RBS.(Also, I think
SomeTypemight have to be a descendent ofNumeric, but the documentation is not clear)