rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Update IO instance methods

Open sampersand opened this issue 1 year ago • 1 comments

Phew! This one took awhile :-P. This PR updates IO's instance methods.

More specifically, this makes the following general changes:

  • Deprecates ::_ReaderPartial (renamed to IO::_Readpartial) and ::_Rewindable (now unused)
  • Deprecates String::_EncodeFallbackAref (moved within to Encoding, as it's used for encoding purposes).
  • Fixes a minor bug in lib/rbs/unit_test/spy.rb where .new() is called instead of .allocate(). This prevents testing instance methods named :initialize.
  • Removed test/stdlib/test_helper.rb:ArefFromStringToString, as it's no longer needed
  • Added in TestHelper::RUBY_EXE, used when spawning shells (IO needs it for IO#pid)
  • Added test/stdlib/util/small-file.txt as a small file that can be read from fro testing
  • Redid all the tests in IO_test.rb to accomodate the with_xxx forms. However, wait_writable and wait_prioroity currently don't have any tests associated with them, as I couldn't figure out a good way to test them. (However, their signatures are pretty simple)

It also makes the following changes to io.rbs:

  • The %a{ruby:since:3.2.0} annotation has been added to methods introduced in ruby 3.2.0
  • Moved all of IO's constant definitions inside of it
  • Removed constant definitions that IO inherits from File::Constants (APPEND, FNM_CASEFOLD, LOCK_SH, etc.)
  • Added IO::EWOULDBLOCKWait{Readable,Writable} constants
  • IO#initialize: mode is now open_mode; updated all the options to be the entire list of accepted options (along with the **untyped that it for some reason accepts)
  • IO#advise: Added IO::advice type alias, offset and len are now int?
  • IO#{lineno,autoclose,sync}=: Now returns their arguments
  • IO#each: Now its own function; each_line aliases it. Also added in the limit-only variant.
  • IO#each_{byte,char,codepoint}: Reordered branches to have Enumerator first
  • IO#external_encoding: Added in. (weird that it didnt exist, since internal_encoding existed before...)
  • IO#{fcntl,ioctl}: Now uses implicits, argument also accepts bool | nil as well.
  • IO#{f{data,}sync,rewind}: Always returns 0
  • IO#pid: Can now return nil
  • IO#pos=: Now takes int
  • IO#p{read,write}: Added in
  • IO#{print,puts}: objects are now _ToS not untyped
  • IO#printf: format string is now string
  • IO#putc: Separated cases out so return values aren't unioned
  • IO#{gets,read}: reordered branches slightly
  • IO#readline{,s}: Added in limit-only variant
  • IO#readpartial: outbuf is now nilable
  • IO#reopen: Changed (IO) -> IO to be (io) -> sef; added in optional keywords to second case
  • IO#seek: amount is now nil; also added in IO::whence type alias.
  • IO#set_encoding: Added in optional encoding arguments
  • IO#sysread: added implicit conversions; outbuf is optional and nilable.
  • IO#sysseek: ADded implicit int for amount; uses IO::whence.
  • IO#timeout=: Now returns self not void (which is weird, since almost every other setter in ruby returns its argument...)
  • IO#to_io: Now marked %a{pure}
  • IO#to_path: Added in
  • IO#ungetbyte: Argument accepts implicit string and is nilable.
  • IO#ungetc: Argument can now be Integer.
  • IO#write_nonblock: Can no longer return nil now

Since Ruby 3.2 moved the wait_* methods into io directly (no need for require 'io/wait'), the methods IO#wait{,_{readable,writable,priority}} have been moved from io/wait.rbs, along with IO::wait_mode and marked as `%a{ruby:since:3.2.0}.

sampersand avatar Dec 20 '23 01:12 sampersand

  • The %a{ruby:since:3.2.0} annotation has been added to methods introduced in ruby 3.2.0

We have Ruby 3.3 now (:

  • #1674

ParadoxV5 avatar Dec 27 '23 00:12 ParadoxV5