-
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
Improve signatures of IO#<<, IO#advise, IO#autoclose=, IO#autoclose? #571
Conversation
# # ... | ||
# f.gets # won't cause Errno::EBADF | ||
# | ||
def autoclose=: (bool) -> bool |
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.
[note] Note that the argument type changes from boolish
to bool
. Because io.autoclose = "yes"
returns "yes"
for example.
We can confirm this behavior as follows:
def test_autoclose=
IO.open(IO.sysopen(__FILE__)) do |io|
assert_send_type "(String) -> bool",
io, :autoclose=, "yes"
end
end
$ bundle exec ruby test/stdlib/IO_test.rb
...
Failure: test_autoclose=(IOInstanceTest):
Call trace does not match with given method type: #<struct RBS::Test::CallTrace method_name=:autoclose=, method_call=#<RBS::Test::ArgumentsReturn:0x00007fa2aea9ac38 @arguments=["yes"], @exit_value="yes", @exit_type=:return>, block_calls=[], block_given=false>.
<["[IOautoclose=] ReturnTypeError: expected `bool` but returns `\"yes\"`"]> was expected to be empty.
/Users/masafumi.koba/git/ybiquitous/rbs/test/stdlib/test_helper.rb:240:in `assert_send_type'
test/stdlib/IO_test.rb:129:in `block in test_autoclose='
126:
127: def test_autoclose=
128: IO.open(IO.sysopen(__FILE__)) do |io|
=> 129: assert_send_type "(String) -> bool",
130: io, :autoclose=, "yes"
131: end
132: end
test/stdlib/IO_test.rb:128:in `open'
test/stdlib/IO_test.rb:128:in `test_autoclose='
...
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 believe the following Sider issue is closeable:
https://sider.review/gh/repos/174796313/pulls/571#issue-5289513
# # ... | ||
# f.gets # won't cause Errno::EBADF | ||
# | ||
def autoclose=: (bool) -> bool |
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.
[Goodcheck] Prefer
boolish
overbool
for method arguments and block return values (view)See the doc below:
https://github.com/ruby/rbs/blob/78d04a2db0f1c4925d2b13c2939868edf9465d6c/docs/syntax.md#bool-or-boolish
Rule rbs.prefer_boolish
You can close this issue if no need to fix it. Learn more.
See #571 (comment)
Thanks! 🎉 |
This change does the following for some methods of the
IO
class:See the API doc: https://ruby-doc.org/core-3.0.0/IO.html