rbs 3.0.0.dev.2 → 3.0.0.dev.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- data/sig/shims/ripper.rbs +0 -8
data/core/enumerator.rbs
CHANGED
@@ -37,8 +37,10 @@
|
|
37
37
|
# list's elements to strings containing the index and the element as a string
|
38
38
|
# via:
|
39
39
|
#
|
40
|
-
#
|
41
|
-
#
|
40
|
+
# puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
|
41
|
+
# # => ["0:foo", "1:bar", "2:baz"]
|
42
|
+
#
|
43
|
+
# == External Iteration
|
42
44
|
#
|
43
45
|
# An Enumerator can also be used as an external iterator. For example,
|
44
46
|
# Enumerator#next returns the next value of the iterator or raises StopIteration
|
@@ -50,14 +52,44 @@
|
|
50
52
|
# puts e.next # => 3
|
51
53
|
# puts e.next # raises StopIteration
|
52
54
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# underlying iteration method itself has side-effect, e.g. IO#each_line.
|
55
|
+
# `next`, `next_values`, `peek` and `peek_values` are the only methods which use
|
56
|
+
# external iteration (and Array#zip(Enumerable-not-Array) which uses `next`).
|
56
57
|
#
|
57
|
-
#
|
58
|
-
#
|
58
|
+
# These methods do not affect other internal enumeration methods, unless the
|
59
|
+
# underlying iteration method itself has side-effect, e.g. IO#each_line.
|
59
60
|
#
|
60
|
-
#
|
61
|
+
# External iteration differs **significantly** from internal iteration due to
|
62
|
+
# using a Fiber:
|
63
|
+
# - The Fiber adds some overhead compared to internal enumeration.
|
64
|
+
# - The stacktrace will only include the stack from the Enumerator, not above.
|
65
|
+
# - Fiber-local variables are *not* inherited inside the Enumerator Fiber,
|
66
|
+
# which instead starts with no Fiber-local variables.
|
67
|
+
# - Fiber storage variables *are* inherited and are designed
|
68
|
+
# to handle Enumerator Fibers. Assigning to a Fiber storage variable
|
69
|
+
# only affects the current Fiber, so if you want to change state
|
70
|
+
# in the caller Fiber of the Enumerator Fiber, you need to use an
|
71
|
+
# extra indirection (e.g., use some object in the Fiber storage
|
72
|
+
# variable and mutate some ivar of it).
|
73
|
+
#
|
74
|
+
# Concretely:
|
75
|
+
# Thread.current[:fiber_local] = 1
|
76
|
+
# Fiber[:storage_var] = 1
|
77
|
+
# e = Enumerator.new do |y|
|
78
|
+
# p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1
|
79
|
+
# p Fiber[:storage_var] # => 1, inherited
|
80
|
+
# Fiber[:storage_var] += 1
|
81
|
+
# y << 42
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# p e.next # => 42
|
85
|
+
# p Fiber[:storage_var] # => 1 (it ran in a different Fiber)
|
86
|
+
#
|
87
|
+
# e.each { p _1 }
|
88
|
+
# p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber)
|
89
|
+
#
|
90
|
+
# == Convert External Iteration to Internal Iteration
|
91
|
+
#
|
92
|
+
# You can use an external iterator to implement an internal iterator as follows:
|
61
93
|
#
|
62
94
|
# def ext_each(e)
|
63
95
|
# while true
|
@@ -92,6 +124,23 @@
|
|
92
124
|
class Enumerator[unchecked out Elem, out Return] < Object
|
93
125
|
include Enumerable[Elem]
|
94
126
|
|
127
|
+
# <!--
|
128
|
+
# rdoc-file=enumerator.c
|
129
|
+
# - Enumerator.product(*enums) -> enumerator
|
130
|
+
# - Enumerator.product(*enums) { |elts| ... } -> enumerator
|
131
|
+
# -->
|
132
|
+
# Generates a new enumerator object that generates a Cartesian product of given
|
133
|
+
# enumerable objects. This is equivalent to Enumerator::Product.new.
|
134
|
+
#
|
135
|
+
# e = Enumerator.product(1..3, [4, 5])
|
136
|
+
# e.to_a #=> [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]
|
137
|
+
# e.size #=> 6
|
138
|
+
#
|
139
|
+
# When a block is given, calls the block with each N-element array generated and
|
140
|
+
# returns `nil`.
|
141
|
+
#
|
142
|
+
def self.product: [Elem] (*_EachEntry[Elem]) -> Product[Elem]
|
143
|
+
|
95
144
|
# <!--
|
96
145
|
# rdoc-file=enumerator.c
|
97
146
|
# - enum.each { |elm| block } -> obj
|
data/core/errors.rbs
CHANGED
@@ -39,14 +39,15 @@ end
|
|
39
39
|
# exist in two forms,
|
40
40
|
#
|
41
41
|
# one that returns `nil` when the end of file is reached, the other raises
|
42
|
-
#
|
42
|
+
# EOFError.
|
43
43
|
#
|
44
|
-
#
|
44
|
+
# EOFError is a subclass of IOError.
|
45
45
|
#
|
46
46
|
# file = File.open("/etc/hosts")
|
47
47
|
# file.read
|
48
48
|
# file.gets #=> nil
|
49
49
|
# file.readline #=> EOFError: end of file reached
|
50
|
+
# file.close
|
50
51
|
#
|
51
52
|
class EOFError < IOError
|
52
53
|
end
|
@@ -567,6 +568,11 @@ class SyntaxError < ScriptError
|
|
567
568
|
# Construct a SyntaxError exception.
|
568
569
|
#
|
569
570
|
def initialize: (?string msg) -> void
|
571
|
+
|
572
|
+
# <!-- rdoc-file=error.c -->
|
573
|
+
# the path failed to parse
|
574
|
+
#
|
575
|
+
def path: () -> String?
|
570
576
|
end
|
571
577
|
|
572
578
|
# <!-- rdoc-file=error.c -->
|
data/core/exception.rbs
CHANGED
@@ -191,6 +191,47 @@ class Exception < Object
|
|
191
191
|
#
|
192
192
|
def cause: () -> Exception?
|
193
193
|
|
194
|
+
# <!--
|
195
|
+
# rdoc-file=error.c
|
196
|
+
# - exception.detailed_message(highlight: bool, **opt) -> string
|
197
|
+
# -->
|
198
|
+
# Processes a string returned by #message.
|
199
|
+
#
|
200
|
+
# It may add the class name of the exception to the end of the first line. Also,
|
201
|
+
# when `highlight` keyword is true, it adds ANSI escape sequences to make the
|
202
|
+
# message bold.
|
203
|
+
#
|
204
|
+
# If you override this method, it must be tolerant for unknown keyword
|
205
|
+
# arguments. All keyword arguments passed to #full_message are delegated to this
|
206
|
+
# method.
|
207
|
+
#
|
208
|
+
# This method is overridden by did_you_mean and error_highlight to add their
|
209
|
+
# information.
|
210
|
+
#
|
211
|
+
# A user-defined exception class can also define their own `detailed_message`
|
212
|
+
# method to add supplemental information. When `highlight` is true, it can
|
213
|
+
# return a string containing escape sequences, but use widely-supported ones. It
|
214
|
+
# is recommended to limit the following codes:
|
215
|
+
#
|
216
|
+
# * Reset (`\e[0m`)
|
217
|
+
# * Bold (`\e[1m`)
|
218
|
+
# * Underline (`\e[4m`)
|
219
|
+
# * Foreground color except white and black
|
220
|
+
# * Red (`\e[31m`)
|
221
|
+
# * Green (`\e[32m`)
|
222
|
+
# * Yellow (`\e[33m`)
|
223
|
+
# * Blue (`\e[34m`)
|
224
|
+
# * Magenta (`\e[35m`)
|
225
|
+
# * Cyan (`\e[36m`)
|
226
|
+
#
|
227
|
+
#
|
228
|
+
#
|
229
|
+
# Use escape sequences carefully even if `highlight` is true. Do not use escape
|
230
|
+
# sequences to express essential information; the message should be readable
|
231
|
+
# even if all escape sequences are ignored.
|
232
|
+
#
|
233
|
+
def detailed_message: () -> String
|
234
|
+
|
194
235
|
# <!--
|
195
236
|
# rdoc-file=error.c
|
196
237
|
# - exc.exception([string]) -> an_exception or exc
|
data/core/fiber.rbs
CHANGED
@@ -69,13 +69,38 @@
|
|
69
69
|
# blocking and non-blocking fibers' behavior is identical.
|
70
70
|
#
|
71
71
|
# Ruby doesn't provide a scheduler class: it is expected to be implemented by
|
72
|
-
# the user and correspond to Fiber::
|
72
|
+
# the user and correspond to Fiber::Scheduler.
|
73
73
|
#
|
74
74
|
# There is also Fiber.schedule method, which is expected to immediately perform
|
75
75
|
# the given block in a non-blocking manner. Its actual implementation is up to
|
76
76
|
# the scheduler.
|
77
77
|
#
|
78
78
|
class Fiber < Object
|
79
|
+
# <!--
|
80
|
+
# rdoc-file=cont.c
|
81
|
+
# - Fiber[key] -> value
|
82
|
+
# -->
|
83
|
+
# Returns the value of the fiber storage variable identified by `key`.
|
84
|
+
#
|
85
|
+
# The `key` must be a symbol, and the value is set by Fiber#[]= or Fiber#store.
|
86
|
+
#
|
87
|
+
# See also Fiber::[]=.
|
88
|
+
#
|
89
|
+
def self.[]: (Symbol | String) -> untyped
|
90
|
+
|
91
|
+
# <!--
|
92
|
+
# rdoc-file=cont.c
|
93
|
+
# - Fiber[key] = value
|
94
|
+
# -->
|
95
|
+
# Assign `value` to the fiber storage variable identified by `key`. The variable
|
96
|
+
# is created if it doesn't exist.
|
97
|
+
#
|
98
|
+
# `key` must be a Symbol, otherwise a TypeError is raised.
|
99
|
+
#
|
100
|
+
# See also Fiber::[].
|
101
|
+
#
|
102
|
+
def self.[]=: [A] (Symbol | String, A) -> A
|
103
|
+
|
79
104
|
# <!--
|
80
105
|
# rdoc-file=cont.c
|
81
106
|
# - Fiber.blocking? -> false or 1
|
@@ -146,8 +171,8 @@ class Fiber < Object
|
|
146
171
|
#
|
147
172
|
# Note that the behavior described above is how the method is *expected* to
|
148
173
|
# behave, actual behavior is up to the current scheduler's implementation of
|
149
|
-
# Fiber::
|
150
|
-
#
|
174
|
+
# Fiber::Scheduler#fiber method. Ruby doesn't enforce this method to behave in
|
175
|
+
# any particular way.
|
151
176
|
#
|
152
177
|
# If the scheduler is not set, the method raises `RuntimeError (No scheduler is
|
153
178
|
# available!)`.
|
@@ -158,11 +183,11 @@ class Fiber < Object
|
|
158
183
|
# rdoc-file=cont.c
|
159
184
|
# - Fiber.scheduler -> obj or nil
|
160
185
|
# -->
|
161
|
-
# Returns the Fiber scheduler, that was last set for the current thread with
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
186
|
+
# Returns the Fiber scheduler, that was last set for the current thread with
|
187
|
+
# Fiber.set_scheduler. Returns `nil` if no scheduler is set (which is the
|
188
|
+
# default), and non-blocking fibers' behavior is the same as blocking. (see
|
189
|
+
# "Non-blocking fibers" section in class docs for details about the scheduler
|
190
|
+
# concept).
|
166
191
|
#
|
167
192
|
def self.scheduler: () -> untyped?
|
168
193
|
|
@@ -177,8 +202,8 @@ class Fiber < Object
|
|
177
202
|
# finalization (allowing the scheduler to properly manage all non-finished
|
178
203
|
# fibers).
|
179
204
|
#
|
180
|
-
# `scheduler` can be an object of any class corresponding to
|
181
|
-
#
|
205
|
+
# `scheduler` can be an object of any class corresponding to Fiber::Scheduler.
|
206
|
+
# Its implementation is up to the user.
|
182
207
|
#
|
183
208
|
# See also the "Non-blocking fibers" section in class docs.
|
184
209
|
#
|
@@ -197,7 +222,7 @@ class Fiber < Object
|
|
197
222
|
|
198
223
|
# <!--
|
199
224
|
# rdoc-file=cont.c
|
200
|
-
# - Fiber.new(blocking: false) { |*args| ... } -> fiber
|
225
|
+
# - Fiber.new(blocking: false, storage: true) { |*args| ... } -> fiber
|
201
226
|
# -->
|
202
227
|
# Creates new Fiber. Initially, the fiber is not running and can be resumed with
|
203
228
|
# #resume. Arguments to the first #resume call will be passed to the block:
|
@@ -218,7 +243,32 @@ class Fiber < Object
|
|
218
243
|
# Fiber.scheduler defined, the Fiber becomes non-blocking (see "Non-blocking
|
219
244
|
# Fibers" section in class docs).
|
220
245
|
#
|
221
|
-
|
246
|
+
# If the `storage` is unspecified, the default is to inherit a copy of the
|
247
|
+
# storage from the current fiber. This is the same as specifying `storage:
|
248
|
+
# true`.
|
249
|
+
#
|
250
|
+
# Fiber[:x] = 1
|
251
|
+
# Fiber.new do
|
252
|
+
# Fiber[:x] # => 1
|
253
|
+
# Fiber[:x] = 2
|
254
|
+
# end.resume
|
255
|
+
# Fiber[:x] # => 1
|
256
|
+
#
|
257
|
+
# If the given `storage` is `nil`, this function will lazy initialize the
|
258
|
+
# internal storage, which starts as an empty hash.
|
259
|
+
#
|
260
|
+
# Fiber[:x] = "Hello World"
|
261
|
+
# Fiber.new(storage: nil) do
|
262
|
+
# Fiber[:x] # nil
|
263
|
+
# end
|
264
|
+
#
|
265
|
+
# Otherwise, the given `storage` is used as the new fiber's storage, and it must
|
266
|
+
# be an instance of Hash.
|
267
|
+
#
|
268
|
+
# Explicitly using `storage: true` is currently experimental and may change in
|
269
|
+
# the future.
|
270
|
+
#
|
271
|
+
def initialize: (?blocking: boolish, ?storage: true | Hash[Symbol | String, untyped] | nil) { (*untyped) -> void } -> void
|
222
272
|
|
223
273
|
# <!--
|
224
274
|
# rdoc-file=cont.c
|
@@ -357,6 +407,39 @@ class Fiber < Object
|
|
357
407
|
#
|
358
408
|
def resume: (*untyped) -> untyped
|
359
409
|
|
410
|
+
# <!--
|
411
|
+
# rdoc-file=cont.c
|
412
|
+
# - fiber.storage -> hash (dup)
|
413
|
+
# -->
|
414
|
+
# Returns a copy of the storage hash for the fiber. The method can only be
|
415
|
+
# called on the Fiber.current.
|
416
|
+
#
|
417
|
+
def storage: () -> Hash[Symbol | String, untyped]
|
418
|
+
|
419
|
+
# <!--
|
420
|
+
# rdoc-file=cont.c
|
421
|
+
# - fiber.storage = hash
|
422
|
+
# -->
|
423
|
+
# Sets the storage hash for the fiber. This feature is experimental and may
|
424
|
+
# change in the future. The method can only be called on the Fiber.current.
|
425
|
+
#
|
426
|
+
# You should be careful about using this method as you may inadvertently clear
|
427
|
+
# important fiber-storage state. You should mostly prefer to assign specific
|
428
|
+
# keys in the storage using Fiber::[]=.
|
429
|
+
#
|
430
|
+
# You can also use `Fiber.new(storage: nil)` to create a fiber with an empty
|
431
|
+
# storage.
|
432
|
+
#
|
433
|
+
# Example:
|
434
|
+
#
|
435
|
+
# while request = request_queue.pop
|
436
|
+
# # Reset the per-request state:
|
437
|
+
# Fiber.current.storage = nil
|
438
|
+
# handle_request(request)
|
439
|
+
# end
|
440
|
+
#
|
441
|
+
def storage=: (Hash[Symbol | String, untyped]) -> Hash[Symbol | String, untyped]
|
442
|
+
|
360
443
|
# <!--
|
361
444
|
# rdoc-file=cont.c
|
362
445
|
# - to_s()
|