From e4a38a219cbbd587b98198d5a8ce08488c4ca160 Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Thu, 27 Jul 2023 18:48:27 -0600 Subject: [PATCH 1/5] Update io.rbs * Fill in `untyped` as appropriate * Many of them are simply `boolish` or `void` * Patching in `::popen` is my main motivation. Yes, it is ridiculous. * Copy-pasted kwargs for `#initialize` and `::open` * Use `nil` rather than `NilClass` --- core/io.rbs | 71 ++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/core/io.rbs b/core/io.rbs index 3817e3281..9b3dad888 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -694,7 +694,7 @@ class IO < Object # # ... # f.gets # won't cause Errno::EBADF # - def autoclose=: (boolish) -> untyped + def autoclose=: (boolish) -> boolish # @@ -3314,7 +3317,7 @@ class IO < Object # # IO#each is an alias for IO#each_line. # - def each_line: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self + def each_line: (?String sep, ?Integer limit) { (String arg0) -> void } -> self | (?String sep, ?Integer limit) -> ::Enumerator[String, self] # @@ -3352,7 +3355,7 @@ class IO < Object # def eof?: () -> bool - def lines: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self + def lines: (?String sep, ?Integer limit) { (String arg0) -> void } -> self | (?String sep, ?Integer limit) -> ::Enumerator[String, self] # From 4ba898671eafbbb84d301f267a0d787a05dd2bbb Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Thu, 27 Jul 2023 18:54:53 -0600 Subject: [PATCH 2/5] Update io.rbs * Delete nonexistent methods `#bytes`, `#chars`, `#codepoints` and `#lines` * Actually make `#each` an alias of `#each_line` * Fill in arg names for `arg0` --- core/io.rbs | 162 +++++++--------------------------------------------- 1 file changed, 22 insertions(+), 140 deletions(-) diff --git a/core/io.rbs b/core/io.rbs index 9b3dad888..1d055a1f7 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -694,7 +694,7 @@ class IO < Object # # ... # f.gets # won't cause Errno::EBADF # - def autoclose=: (boolish) -> boolish + def autoclose=: (boolish bool) -> boolish # - # Calls the block with each remaining line read from the stream; returns `self`. - # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO). - # - # With no arguments given, reads lines as determined by line separator `$/`: - # - # f = File.new('t.txt') - # f.each_line {|line| p line } - # f.each_line {|line| fail 'Cannot happen' } - # f.close - # - # Output: - # - # "First line\n" - # "Second line\n" - # "\n" - # "Fourth line\n" - # "Fifth line\n" - # - # With only string argument `sep` given, reads lines as determined by line - # separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator): - # - # f = File.new('t.txt') - # f.each_line('li') {|line| p line } - # f.close - # - # Output: - # - # "First li" - # "ne\nSecond li" - # "ne\n\nFourth li" - # "ne\nFifth li" - # "ne\n" - # - # The two special values for `sep` are honored: - # - # f = File.new('t.txt') - # # Get all into one string. - # f.each_line(nil) {|line| p line } - # f.close - # - # Output: - # - # "First line\nSecond line\n\nFourth line\nFifth line\n" - # - # f.rewind - # # Get paragraphs (up to two line separators). - # f.each_line('') {|line| p line } - # - # Output: - # - # "First line\nSecond line\n\n" - # "Fourth line\nFifth line\n" - # - # With only integer argument `limit` given, limits the number of bytes in each - # line; see [Line Limit](rdoc-ref:IO@Line+Limit): - # - # f = File.new('t.txt') - # f.each_line(8) {|line| p line } - # f.close - # - # Output: - # - # "First li" - # "ne\n" - # "Second l" - # "ine\n" - # "\n" - # "Fourth l" - # "ine\n" - # "Fifth li" - # "ne\n" - # - # With arguments `sep` and `limit` given, combines the two behaviors: - # - # * Calls with the next line as determined by line separator `sep`. - # * But returns no more bytes than are allowed by the limit. - # - # - # Optional keyword argument `chomp` specifies whether line separators are to be - # omitted: - # - # f = File.new('t.txt') - # f.each_line(chomp: true) {|line| p line } - # f.close - # - # Output: - # - # "First line" - # "Second line" - # "" - # "Fourth line" - # "Fifth line" - # - # Returns an Enumerator if no block is given. - # - # IO#each is an alias for IO#each_line. - # - def each: (?String sep, ?Integer limit) { (String arg0) -> void } -> self - | (?String sep, ?Integer limit) -> ::Enumerator[String, self] - + # # Calls the block with each remaining line read from the stream; returns `self`. # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO). @@ -3317,8 +3201,9 @@ class IO < Object # # IO#each is an alias for IO#each_line. # - def each_line: (?String sep, ?Integer limit) { (String arg0) -> void } -> self + def each_line: (?String sep, ?Integer limit) { (String line) -> void } -> self | (?String sep, ?Integer limit) -> ::Enumerator[String, self] + alias each each_line # # Returns `true` if the stream is positioned at its end, `false` otherwise; see @@ -3355,9 +3240,6 @@ class IO < Object # def eof?: () -> bool - def lines: (?String sep, ?Integer limit) { (String arg0) -> void } -> self - | (?String sep, ?Integer limit) -> ::Enumerator[String, self] - # # Returns the integer file descriptor for the stream: # From dc5980966fe428c4b9f9447ecbf2d31b61276eab Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Thu, 27 Jul 2023 19:01:07 -0600 Subject: [PATCH 3/5] `rake annotate` (select changes) --- core/io.rbs | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/core/io.rbs b/core/io.rbs index 1d055a1f7..660f8b82f 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -879,7 +879,7 @@ class IO < Object # Related: IO#close_read, IO#close_write, IO#close. # def closed?: () -> bool - + # + # Calls the block with each remaining line read from the stream; returns `self`. + # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO). + # + # With no arguments given, reads lines as determined by line separator `$/`: + # + # f = File.new('t.txt') + # f.each_line {|line| p line } + # f.each_line {|line| fail 'Cannot happen' } + # f.close + # + # Output: + # + # "First line\n" + # "Second line\n" + # "\n" + # "Fourth line\n" + # "Fifth line\n" + # + # With only string argument `sep` given, reads lines as determined by line + # separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator): + # + # f = File.new('t.txt') + # f.each_line('li') {|line| p line } + # f.close + # + # Output: + # + # "First li" + # "ne\nSecond li" + # "ne\n\nFourth li" + # "ne\nFifth li" + # "ne\n" + # + # The two special values for `sep` are honored: + # + # f = File.new('t.txt') + # # Get all into one string. + # f.each_line(nil) {|line| p line } + # f.close + # + # Output: + # + # "First line\nSecond line\n\nFourth line\nFifth line\n" + # + # f.rewind + # # Get paragraphs (up to two line separators). + # f.each_line('') {|line| p line } + # + # Output: + # + # "First line\nSecond line\n\n" + # "Fourth line\nFifth line\n" + # + # With only integer argument `limit` given, limits the number of bytes in each + # line; see [Line Limit](rdoc-ref:IO@Line+Limit): + # + # f = File.new('t.txt') + # f.each_line(8) {|line| p line } + # f.close + # + # Output: + # + # "First li" + # "ne\n" + # "Second l" + # "ine\n" + # "\n" + # "Fourth l" + # "ine\n" + # "Fifth li" + # "ne\n" + # + # With arguments `sep` and `limit` given, combines the two behaviors: + # + # * Calls with the next line as determined by line separator `sep`. + # * But returns no more bytes than are allowed by the limit. + # + # + # Optional keyword argument `chomp` specifies whether line separators are to be + # omitted: + # + # f = File.new('t.txt') + # f.each_line(chomp: true) {|line| p line } + # f.close + # + # Output: + # + # "First line" + # "Second line" + # "" + # "Fourth line" + # "Fifth line" + # + # Returns an Enumerator if no block is given. + # + # IO#each is an alias for IO#each_line. + # alias each each_line # From 242026f15d19d7bfc06a9636426590886b7e2338 Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Thu, 27 Jul 2023 19:11:21 -0600 Subject: [PATCH 4/5] `io.rbs`: More aliases --- core/io.rbs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/core/io.rbs b/core/io.rbs index 660f8b82f..5ebe8149c 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -1314,22 +1314,6 @@ class IO < Object # def pid: () -> Integer - # - # Returns the current position (in bytes) in `self` (see - # [Position](rdoc-ref:IO@Position)): - # - # f = File.open('t.txt') - # f.tell # => 0 - # f.gets # => "First line\n" - # f.tell # => 12 - # f.close - # - # Related: IO#pos=, IO#seek. - # - # IO#pos is an alias for IO#tell. - # - def pos: () -> Integer - # + # Returns the current position (in bytes) in `self` (see + # [Position](rdoc-ref:IO@Position)): + # + # f = File.open('t.txt') + # f.tell # => 0 + # f.gets # => "First line\n" + # f.tell # => 12 + # f.close + # + # Related: IO#pos=, IO#seek. + # + # IO#pos is an alias for IO#tell. + # + alias pos tell + # # Returns the integer file descriptor for the stream: @@ -3357,7 +3357,7 @@ class IO < Object # # IO#to_i is an alias for IO#fileno. # - def to_i: () -> Integer + alias to_i fileno end IO::APPEND: Integer From 76e78061335142d96bda7bf67abd6f1d3204737a Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Mon, 14 Aug 2023 17:09:23 +0900 Subject: [PATCH 5/5] Fixup encoding keyword types and kwargs names --- core/io.rbs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/io.rbs b/core/io.rbs index 5ebe8149c..ffff2d5ba 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -1202,7 +1202,7 @@ class IO < Object # IO.new(fd, internal_encoding: nil) # => # # IO.new(fd, autoclose: true) # => # # - def initialize: (int fd, ?string | int mode, ?path: string?, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: boolish textmode, ?binmode: boolish binmode, ?autoclose: boolish autoclose, ?mode: String mode) -> void + def initialize: ( int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> void # # Calls the block with each remaining line read from the stream; returns `self`.