-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add signature of Timeout #586
Conversation
stdlib/timeout/0/timeout.rbs
Outdated
# Timeout` into your classes so they have a #timeout method, as well as a module | ||
# method, so you can call it directly as Timeout.timeout(). | ||
# | ||
def self.timeout: (Numeric? sec, ?singleton(Exception) klass, ?String message) { (Numeric sec) -> untyped } -> untyped |
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.
How about using self?
instead of defining singleton and instance methods individually?
https://github.com/ruby/rbs/blob/26baa08e184d1d27c18a34e6683493db42f5fe77/docs/syntax.md#method-definition
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.
Thank you for your recommendations.
I fixed it in 5ff07e8
test/stdlib/Timeout_test.rb
Outdated
hard_process = Proc.new { _calc_pi } | ||
refute_send_type "(::Numeric sec) { (::Numeric sec) -> untyped } -> untyped", | ||
Timeout, :timeout, 0.001, &hard_process | ||
refute_send_type "(::Numeric sec, singleton(Exception) klass) { (::Numeric sec) -> untyped } -> untyped", | ||
Timeout, :timeout, 0.001, TimeoutTestException, &hard_process | ||
refute_send_type "(::Numeric sec, singleton(Exception) klass, String message) { (::Numeric sec) -> untyped } -> untyped", | ||
Timeout, :timeout, 0.001, TimeoutTestException, "timeout test error", &hard_process |
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 not sure that this refute_send_type
usage is appropriate.
I guess refute_send_type
is designed to check an unacceptable type. For example, Timeout.timeout('1')
is invalid with the type, so checking Timeout.timeout('1')
call with refute_send_type
is the designed usage.
But these tests, such as Timeout.timeout(0.001){...}
, is acceptable with the type. It just checks Timeout.timeout
raises an error, but the raised error is an "expected" error. So the refute_send_type
calls just suppress the error. I think refute_send_type
is not appropriate in this case.
related: #588
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.
Thank you for your advice! I can understand.
I fixed it in 083beb9 . Would you please review again.
Co-authored-by: Masataka Pocke Kuwabara <[email protected]>
Thanks for your contribution! 👏 I merged this pull request with a small fix 6119e0d. |
This PR add signature of Timeout module.
NOTE: Timeout module has sub module(ex:
Timeout::Error
).But, I first wrote in rbs. So, this is first step and doesn't include the sub module.