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

Improve signatures of IO#<<, IO#advise, IO#autoclose=, IO#autoclose? #571

Merged
merged 1 commit into from
Jan 16, 2021
Merged

Improve signatures of IO#<<, IO#advise, IO#autoclose=, IO#autoclose? #571

merged 1 commit into from
Jan 16, 2021

Conversation

ybiquitous
Copy link
Contributor

@ybiquitous ybiquitous commented Jan 8, 2021

This change does the following for some methods of the IO class:

  • add missing documents
  • add tests
  • make some types more accurate

See the API doc: https://ruby-doc.org/core-3.0.0/IO.html

# # ...
# f.gets # won't cause Errno::EBADF
#
def autoclose=: (bool) -> bool
Copy link
Contributor Author

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='
...

Copy link
Contributor Author

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

@ybiquitous ybiquitous marked this pull request as ready for review January 8, 2021 00:51
# # ...
# f.gets # won't cause Errno::EBADF
#
def autoclose=: (bool) -> bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Goodcheck] Prefer boolish over bool 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)

@soutaro soutaro merged commit 5cf1eca into ruby:master Jan 16, 2021
@soutaro
Copy link
Member

soutaro commented Jan 16, 2021

Thanks! 🎉

@ybiquitous ybiquitous deleted the add-signature-io-methods branch January 16, 2021 08:50
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