Skip to content
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

Merged
merged 10 commits into from
Feb 11, 2021
Merged

Add signature of Timeout #586

merged 10 commits into from
Feb 11, 2021

Conversation

m11o
Copy link
Contributor

@m11o m11o commented Feb 2, 2021

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.

# 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
Copy link
Member

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

Copy link
Contributor Author

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

stdlib/timeout/0/timeout.rbs Outdated Show resolved Hide resolved
Comment on lines 24 to 30
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
Copy link
Member

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

Copy link
Contributor Author

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.

@pocke pocke merged commit 90f373e into ruby:master Feb 11, 2021
@pocke
Copy link
Member

pocke commented Feb 11, 2021

Thanks for your contribution! 👏 I merged this pull request with a small fix 6119e0d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants