rbs 0.12.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +31 -0
  5. data/Gemfile +3 -0
  6. data/README.md +8 -2
  7. data/Rakefile +2 -2
  8. data/Steepfile +1 -0
  9. data/bin/annotate-with-rdoc +1 -1
  10. data/bin/setup +0 -2
  11. data/docs/CONTRIBUTING.md +1 -0
  12. data/docs/syntax.md +50 -6
  13. data/goodcheck.yml +22 -5
  14. data/lib/rbs/ast/comment.rb +1 -1
  15. data/lib/rbs/cli.rb +12 -4
  16. data/lib/rbs/constant.rb +1 -1
  17. data/lib/rbs/constant_table.rb +9 -8
  18. data/lib/rbs/definition_builder.rb +6 -7
  19. data/lib/rbs/environment.rb +5 -1
  20. data/lib/rbs/environment_loader.rb +12 -12
  21. data/lib/rbs/namespace.rb +1 -1
  22. data/lib/rbs/parser.rb +3148 -0
  23. data/lib/rbs/parser.y +10 -3
  24. data/lib/rbs/prototype/rb.rb +38 -6
  25. data/lib/rbs/prototype/runtime.rb +17 -7
  26. data/lib/rbs/test/hook.rb +2 -0
  27. data/lib/rbs/test/setup_helper.rb +4 -4
  28. data/lib/rbs/test/tester.rb +4 -1
  29. data/lib/rbs/test/type_check.rb +12 -6
  30. data/lib/rbs/type_name.rb +1 -1
  31. data/lib/rbs/variance_calculator.rb +2 -2
  32. data/lib/rbs/version.rb +1 -1
  33. data/lib/rbs/writer.rb +25 -15
  34. data/sig/constant.rbs +21 -0
  35. data/sig/constant_table.rbs +30 -0
  36. data/sig/declarations.rbs +2 -2
  37. data/sig/definition.rbs +2 -2
  38. data/sig/definition_builder.rbs +4 -5
  39. data/sig/environment_loader.rbs +54 -0
  40. data/sig/members.rbs +2 -2
  41. data/sig/method_types.rbs +1 -1
  42. data/sig/namespace.rbs +4 -4
  43. data/sig/parser.rbs +25 -0
  44. data/sig/substitution.rbs +3 -3
  45. data/sig/typename.rbs +1 -1
  46. data/sig/types.rbs +1 -1
  47. data/sig/version.rbs +3 -0
  48. data/sig/writer.rbs +40 -0
  49. data/stdlib/base64/base64.rbs +1 -1
  50. data/stdlib/benchmark/benchmark.rbs +2 -2
  51. data/stdlib/builtin/array.rbs +124 -120
  52. data/stdlib/builtin/basic_object.rbs +54 -54
  53. data/stdlib/builtin/binding.rbs +42 -42
  54. data/stdlib/builtin/builtin.rbs +28 -0
  55. data/stdlib/builtin/class.rbs +33 -33
  56. data/stdlib/builtin/complex.rbs +90 -90
  57. data/stdlib/builtin/encoding.rbs +33 -33
  58. data/stdlib/builtin/enumerable.rbs +58 -52
  59. data/stdlib/builtin/enumerator.rbs +35 -35
  60. data/stdlib/builtin/errors.rbs +2 -2
  61. data/stdlib/builtin/exception.rbs +50 -50
  62. data/stdlib/builtin/false_class.rbs +6 -6
  63. data/stdlib/builtin/fiber.rbs +14 -14
  64. data/stdlib/builtin/fiber_error.rbs +1 -1
  65. data/stdlib/builtin/float.rbs +161 -161
  66. data/stdlib/builtin/gc.rbs +3 -3
  67. data/stdlib/builtin/hash.rbs +7 -7
  68. data/stdlib/builtin/io.rbs +88 -88
  69. data/stdlib/builtin/kernel.rbs +71 -153
  70. data/stdlib/builtin/match_data.rbs +1 -1
  71. data/stdlib/builtin/method.rbs +19 -19
  72. data/stdlib/builtin/module.rbs +13 -13
  73. data/stdlib/builtin/nil_class.rbs +20 -20
  74. data/stdlib/builtin/numeric.rbs +101 -101
  75. data/stdlib/builtin/object.rbs +173 -173
  76. data/stdlib/builtin/proc.rbs +91 -91
  77. data/stdlib/builtin/random.rbs +1 -1
  78. data/stdlib/builtin/range.rbs +3 -5
  79. data/stdlib/builtin/rational.rbs +83 -83
  80. data/stdlib/builtin/signal.rbs +7 -7
  81. data/stdlib/builtin/string.rbs +10 -10
  82. data/stdlib/builtin/string_io.rbs +8 -8
  83. data/stdlib/builtin/struct.rbs +1 -1
  84. data/stdlib/builtin/symbol.rbs +1 -1
  85. data/stdlib/builtin/thread.rbs +189 -189
  86. data/stdlib/builtin/thread_group.rbs +2 -2
  87. data/stdlib/builtin/true_class.rbs +10 -10
  88. data/stdlib/builtin/warning.rbs +1 -1
  89. data/stdlib/coverage/coverage.rbs +2 -2
  90. data/stdlib/csv/csv.rbs +1 -1
  91. data/stdlib/date/date.rbs +4 -4
  92. data/stdlib/date/date_time.rbs +1 -1
  93. data/stdlib/find/find.rbs +12 -12
  94. data/stdlib/logger/log_device.rbs +1 -1
  95. data/stdlib/logger/logger.rbs +1 -1
  96. data/stdlib/pathname/pathname.rbs +41 -39
  97. data/stdlib/pstore/pstore.rbs +287 -0
  98. data/stdlib/pty/pty.rbs +5 -29
  99. data/stdlib/tmpdir/tmpdir.rbs +12 -12
  100. data/stdlib/uri/generic.rbs +2 -2
  101. data/stdlib/uri/http.rbs +158 -0
  102. data/stdlib/uri/https.rbs +108 -0
  103. data/stdlib/uri/ldap.rbs +224 -0
  104. data/stdlib/uri/ldaps.rbs +108 -0
  105. data/steep/Gemfile.lock +13 -17
  106. metadata +13 -3
@@ -1,59 +1,59 @@
1
1
  # A class which allows both internal and external iteration.
2
- #
2
+ #
3
3
  # An [Enumerator](Enumerator) can be created by the
4
4
  # following methods.
5
- #
5
+ #
6
6
  # - Kernel\#to\_enum
7
- #
7
+ #
8
8
  # - Kernel\#enum\_for
9
- #
9
+ #
10
10
  # - [::new](Enumerator#method-c-new)
11
- #
11
+ #
12
12
  # Most methods have two forms: a block form where the contents are
13
13
  # evaluated for each item in the enumeration, and a non-block form which
14
14
  # returns a new [Enumerator](Enumerator) wrapping the
15
15
  # iteration.
16
- #
16
+ #
17
17
  # ```ruby
18
18
  # enumerator = %w(one two three).each
19
19
  # puts enumerator.class # => Enumerator
20
- #
20
+ #
21
21
  # enumerator.each_with_object("foo") do |item, obj|
22
22
  # puts "#{obj}: #{item}"
23
23
  # end
24
- #
24
+ #
25
25
  # # foo: one
26
26
  # # foo: two
27
27
  # # foo: three
28
- #
28
+ #
29
29
  # enum_with_obj = enumerator.each_with_object("foo")
30
30
  # puts enum_with_obj.class # => Enumerator
31
- #
31
+ #
32
32
  # enum_with_obj.each do |item, obj|
33
33
  # puts "#{obj}: #{item}"
34
34
  # end
35
- #
35
+ #
36
36
  # # foo: one
37
37
  # # foo: two
38
38
  # # foo: three
39
39
  # ```
40
- #
40
+ #
41
41
  # This allows you to chain Enumerators together. For example, you can map
42
42
  # a list's elements to strings containing the index and the element as a
43
43
  # string via:
44
- #
44
+ #
45
45
  # ```ruby
46
46
  # puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
47
47
  # # => ["0:foo", "1:bar", "2:baz"]
48
48
  # ```
49
- #
49
+ #
50
50
  # An [Enumerator](Enumerator) can also be used as an
51
51
  # external iterator. For example,
52
52
  # [\#next](Enumerator#method-i-next) returns the next
53
53
  # value of the iterator or raises
54
54
  # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) if
55
55
  # the [Enumerator](Enumerator) is at the end.
56
- #
56
+ #
57
57
  # ```ruby
58
58
  # e = [1,2,3].each # returns an enumerator object.
59
59
  # puts e.next # => 1
@@ -61,9 +61,9 @@
61
61
  # puts e.next # => 3
62
62
  # puts e.next # raises StopIteration
63
63
  # ```
64
- #
64
+ #
65
65
  # You can use this to implement an internal iterator as follows:
66
- #
66
+ #
67
67
  # ```ruby
68
68
  # def ext_each(e)
69
69
  # while true
@@ -76,20 +76,20 @@
76
76
  # e.feed y
77
77
  # end
78
78
  # end
79
- #
79
+ #
80
80
  # o = Object.new
81
- #
81
+ #
82
82
  # def o.each
83
83
  # puts yield
84
84
  # puts yield(1)
85
85
  # puts yield(1, 2)
86
86
  # 3
87
87
  # end
88
- #
88
+ #
89
89
  # # use o.each as an internal iterator directly.
90
90
  # puts o.each {|*x| puts x; [:b, *x] }
91
91
  # # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3
92
- #
92
+ #
93
93
  # # convert o.each to an external iterator for
94
94
  # # implementing an internal iterator.
95
95
  # puts ext_each(o.to_enum) {|*x| puts x; [:b, *x] }
@@ -112,8 +112,8 @@ class Enumerator[unchecked out Elem, out Return] < Object
112
112
  # position forward. When the position reached at the end,
113
113
  # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
114
114
  # raised.
115
- #
116
- #
115
+ #
116
+ #
117
117
  # ```ruby
118
118
  # a = [1,2,3]
119
119
  # e = a.to_enum
@@ -122,7 +122,7 @@ class Enumerator[unchecked out Elem, out Return] < Object
122
122
  # p e.next #=> 3
123
123
  # p e.next #raises StopIteration
124
124
  # ```
125
- #
125
+ #
126
126
  # Note that enumeration sequence by `next` does not affect other
127
127
  # non-external enumeration methods, unless the underlying iteration
128
128
  # methods itself has side-effect, e.g.
@@ -134,10 +134,10 @@ class Enumerator[unchecked out Elem, out Return] < Object
134
134
  # internal position forward. When the position reached at the end,
135
135
  # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
136
136
  # raised.
137
- #
137
+ #
138
138
  # This method can be used to distinguish `yield` and `yield nil` .
139
- #
140
- #
139
+ #
140
+ #
141
141
  # ```ruby
142
142
  # o = Object.new
143
143
  # def o.each
@@ -159,7 +159,7 @@ class Enumerator[unchecked out Elem, out Return] < Object
159
159
  # p e.next
160
160
  # p e.next
161
161
  # p e.next
162
- #
162
+ #
163
163
  # ## yield args next_values next
164
164
  # # yield [] nil
165
165
  # # yield 1 [1] 1
@@ -167,7 +167,7 @@ class Enumerator[unchecked out Elem, out Return] < Object
167
167
  # # yield nil [nil] nil
168
168
  # # yield [1, 2] [[1, 2]] [1, 2]
169
169
  # ```
170
- #
170
+ #
171
171
  # Note that `next_values` does not affect other non-external enumeration
172
172
  # methods unless underlying iteration method itself has side-effect, e.g.
173
173
  # [IO\#each\_line](https://ruby-doc.org/core-2.6.3/IO.html#method-i-each_line)
@@ -178,8 +178,8 @@ class Enumerator[unchecked out Elem, out Return] < Object
178
178
  # position forward. If the position is already at the end,
179
179
  # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
180
180
  # raised.
181
- #
182
- #
181
+ #
182
+ #
183
183
  # ```ruby
184
184
  # a = [1,2,3]
185
185
  # e = a.to_enum
@@ -199,8 +199,8 @@ class Enumerator[unchecked out Elem, out Return] < Object
199
199
  # already at the end,
200
200
  # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html) is
201
201
  # raised.
202
- #
203
- #
202
+ #
203
+ #
204
204
  # ```ruby
205
205
  # o = Object.new
206
206
  # def o.each
@@ -221,13 +221,13 @@ class Enumerator[unchecked out Elem, out Return] < Object
221
221
  def peek_values: () -> ::Array[Elem]
222
222
 
223
223
  # Rewinds the enumeration sequence to the beginning.
224
- #
224
+ #
225
225
  # If the enclosed object responds to a “rewind” method, it is called.
226
226
  def rewind: () -> self
227
227
 
228
228
  # Returns the size of the enumerator, or `nil` if it can’t be calculated
229
229
  # lazily.
230
- #
230
+ #
231
231
  # ```ruby
232
232
  # (1..100).to_a.permutation(4).size # => 94109400
233
233
  # loop.size # => Float::INFINITY
@@ -20,7 +20,7 @@
20
20
  class ArgumentError < StandardError
21
21
  end
22
22
 
23
- # The exception class which will be raised when pushing into a closed Queue.
23
+ # The exception class which will be raised when pushing into a closed Queue.
24
24
  # See Queue#close and SizedQueue#close.
25
25
  #
26
26
  class ClosedQueueError < StopIteration
@@ -266,7 +266,7 @@ class NoMethodError[T] < NameError[T]
266
266
  #
267
267
  # *receiver* argument stores an object whose method was called.
268
268
  #
269
- def initialize: (?string? msg, ?String? name, ?Array[untyped] args, ?bool `private`, ?receiver: T?) -> void
269
+ def initialize: (?string? msg, ?String? name, ?Array[untyped] args, ?boolish `private`, ?receiver: T?) -> void
270
270
 
271
271
  public
272
272
 
@@ -9,19 +9,19 @@
9
9
  # information like
10
10
  # [NameError\#name](https://ruby-doc.org/core-2.6.3/NameError.html#method-i-name)
11
11
  # .
12
- #
12
+ #
13
13
  # Programs may make subclasses of
14
14
  # [Exception](Exception), typically of
15
15
  # [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
16
16
  # [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html), to
17
17
  # provide custom classes and add additional information. See the subclass
18
18
  # list below for defaults for `raise` and `rescue` .
19
- #
19
+ #
20
20
  # When an exception has been raised but not yet handled (in `rescue`,
21
21
  # `ensure`, `at_exit` and `END` blocks) the global variable `$!` will
22
22
  # contain the current exception and `$@` contains the current exception’s
23
23
  # backtrace.
24
- #
24
+ #
25
25
  # It is recommended that a library should have one subclass of
26
26
  # [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
27
27
  # [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html) and
@@ -29,97 +29,97 @@
29
29
  # rescue a generic exception type to catch all exceptions the library may
30
30
  # raise even if future versions of the library add new exception
31
31
  # subclasses.
32
- #
32
+ #
33
33
  # For example:
34
- #
34
+ #
35
35
  # ```ruby
36
36
  # class MyLibrary
37
37
  # class Error < RuntimeError
38
38
  # end
39
- #
39
+ #
40
40
  # class WidgetError < Error
41
41
  # end
42
- #
42
+ #
43
43
  # class FrobError < Error
44
44
  # end
45
- #
45
+ #
46
46
  # end
47
47
  # ```
48
- #
48
+ #
49
49
  # To handle both WidgetError and FrobError the library user can rescue
50
50
  # MyLibrary::Error.
51
- #
51
+ #
52
52
  # The built-in subclasses of [Exception](Exception)
53
53
  # are:
54
- #
54
+ #
55
55
  # - [NoMemoryError](https://ruby-doc.org/core-2.6.3/NoMemoryError.html)
56
- #
56
+ #
57
57
  # - [ScriptError](https://ruby-doc.org/core-2.6.3/ScriptError.html)
58
- #
58
+ #
59
59
  # - [LoadError](https://ruby-doc.org/core-2.6.3/LoadError.html)
60
- #
60
+ #
61
61
  # - [NotImplementedError](https://ruby-doc.org/core-2.6.3/NotImplementedError.html)
62
- #
62
+ #
63
63
  # - [SyntaxError](https://ruby-doc.org/core-2.6.3/SyntaxError.html)
64
- #
64
+ #
65
65
  # - [SecurityError](https://ruby-doc.org/core-2.6.3/SecurityError.html)
66
- #
66
+ #
67
67
  # - [SignalException](https://ruby-doc.org/core-2.6.3/SignalException.html)
68
- #
68
+ #
69
69
  # - [Interrupt](https://ruby-doc.org/core-2.6.3/Interrupt.html)
70
- #
70
+ #
71
71
  # - [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html)
72
72
  # -- default for `rescue`
73
- #
73
+ #
74
74
  # - [ArgumentError](https://ruby-doc.org/core-2.6.3/ArgumentError.html)
75
- #
75
+ #
76
76
  # - [UncaughtThrowError](https://ruby-doc.org/core-2.6.3/UncaughtThrowError.html)
77
- #
77
+ #
78
78
  # - [EncodingError](https://ruby-doc.org/core-2.6.3/EncodingError.html)
79
- #
79
+ #
80
80
  # - [FiberError](https://ruby-doc.org/core-2.6.3/FiberError.html)
81
- #
81
+ #
82
82
  # - [IOError](https://ruby-doc.org/core-2.6.3/IOError.html)
83
- #
83
+ #
84
84
  # - [EOFError](https://ruby-doc.org/core-2.6.3/EOFError.html)
85
- #
85
+ #
86
86
  # - [IndexError](https://ruby-doc.org/core-2.6.3/IndexError.html)
87
- #
87
+ #
88
88
  # - [KeyError](https://ruby-doc.org/core-2.6.3/KeyError.html)
89
- #
89
+ #
90
90
  # - [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
91
- #
91
+ #
92
92
  # - [LocalJumpError](https://ruby-doc.org/core-2.6.3/LocalJumpError.html)
93
- #
93
+ #
94
94
  # - [NameError](https://ruby-doc.org/core-2.6.3/NameError.html)
95
- #
95
+ #
96
96
  # - [NoMethodError](https://ruby-doc.org/core-2.6.3/NoMethodError.html)
97
- #
97
+ #
98
98
  # - [RangeError](https://ruby-doc.org/core-2.6.3/RangeError.html)
99
- #
99
+ #
100
100
  # - [FloatDomainError](https://ruby-doc.org/core-2.6.3/FloatDomainError.html)
101
- #
101
+ #
102
102
  # - [RegexpError](https://ruby-doc.org/core-2.6.3/RegexpError.html)
103
- #
103
+ #
104
104
  # - [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
105
105
  # -- default for `raise`
106
- #
106
+ #
107
107
  # - [FrozenError](https://ruby-doc.org/core-2.6.3/FrozenError.html)
108
- #
108
+ #
109
109
  # - [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
110
- #
110
+ #
111
111
  # - Errno::\*
112
- #
112
+ #
113
113
  # - [ThreadError](https://ruby-doc.org/core-2.6.3/ThreadError.html)
114
- #
114
+ #
115
115
  # - [TypeError](https://ruby-doc.org/core-2.6.3/TypeError.html)
116
- #
116
+ #
117
117
  # - [ZeroDivisionError](https://ruby-doc.org/core-2.6.3/ZeroDivisionError.html)
118
- #
118
+ #
119
119
  # - [SystemExit](https://ruby-doc.org/core-2.6.3/SystemExit.html)
120
- #
120
+ #
121
121
  # - [SystemStackError](https://ruby-doc.org/core-2.6.3/SystemStackError.html)
122
- #
122
+ #
123
123
  # - fatal – impossible to rescue
124
124
  class Exception < Object
125
125
  def self.to_tty?: () -> bool
@@ -131,25 +131,25 @@ class Exception < Object
131
131
  # Returns any backtrace associated with the exception. The backtrace is an
132
132
  # array of strings, each containing either “filename:lineNo: in \`method”‘
133
133
  # or “filename:lineNo.”
134
- #
134
+ #
135
135
  # ```ruby
136
136
  # def a
137
137
  # raise "boom"
138
138
  # end
139
- #
139
+ #
140
140
  # def b
141
141
  # a()
142
142
  # end
143
- #
143
+ #
144
144
  # begin
145
145
  # b()
146
146
  # rescue => detail
147
147
  # print detail.backtrace.join("\n")
148
148
  # end
149
149
  # ```
150
- #
150
+ #
151
151
  # *produces:*
152
- #
152
+ #
153
153
  # prog.rb:2:in `a'
154
154
  # prog.rb:6:in `b'
155
155
  # prog.rb:10
@@ -161,7 +161,7 @@ class Exception < Object
161
161
  # the backtrace is an array of
162
162
  # [Thread::Backtrace::Location](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
163
163
  # .
164
- #
164
+ #
165
165
  # Now, this method is not affected by
166
166
  # [\#set\_backtrace](Exception.downloaded.ruby_doc#method-i-set_backtrace)
167
167
  # .
@@ -1,7 +1,7 @@
1
1
  # The global value `false` is the only instance of class FalseClass and
2
2
  # represents a logically false value in boolean expressions. The class provides
3
3
  # operators allowing `false` to participate correctly in logical expressions.
4
- #
4
+ #
5
5
  class FalseClass
6
6
  public
7
7
 
@@ -9,19 +9,19 @@ class FalseClass
9
9
 
10
10
  # And---Returns `false`. *obj* is always evaluated as it is the argument to a
11
11
  # method call---there is no short-circuit evaluation in this case.
12
- #
12
+ #
13
13
  def &: (untyped obj) -> bool
14
14
 
15
15
  # Case Equality -- For class Object, effectively the same as calling `#==`, but
16
16
  # typically overridden by descendants to provide meaningful semantics in `case`
17
17
  # statements.
18
- #
18
+ #
19
19
  def ===: (false) -> true
20
20
  | (untyped obj) -> bool
21
21
 
22
22
  # Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
23
23
  # returns `true`.
24
- #
24
+ #
25
25
  def ^: (nil) -> false
26
26
  | (false) -> false
27
27
  | (untyped obj) -> bool
@@ -29,11 +29,11 @@ class FalseClass
29
29
  alias inspect to_s
30
30
 
31
31
  # The string representation of `false` is "false".
32
- #
32
+ #
33
33
  def to_s: () -> "false"
34
34
 
35
35
  # Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
36
- #
36
+ #
37
37
  def |: (nil) -> false
38
38
  | (false) -> false
39
39
  | (untyped obj) -> bool