rbs 3.3.2 → 3.4.0.pre.1
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 -5
- data/.github/workflows/ruby.yml +7 -8
- data/.github/workflows/typecheck.yml +37 -0
- data/CHANGELOG.md +50 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/Steepfile +2 -2
- data/core/array.rbs +19 -49
- data/core/basic_object.rbs +2 -2
- data/core/comparable.rbs +17 -8
- data/core/complex.rbs +82 -43
- data/core/data.rbs +2 -4
- data/core/dir.rbs +635 -295
- data/core/enumerable.rbs +11 -18
- data/core/enumerator.rbs +37 -31
- data/core/errors.rbs +4 -0
- data/core/false_class.rbs +34 -15
- data/core/fiber.rbs +23 -0
- data/core/file.rbs +329 -120
- data/core/float.rbs +17 -32
- data/core/gc.rbs +17 -11
- data/core/hash.rbs +22 -44
- data/core/integer.rbs +82 -113
- data/core/io/buffer.rbs +90 -47
- data/core/io.rbs +39 -116
- data/core/kernel.rbs +442 -489
- data/core/match_data.rbs +55 -56
- data/core/module.rbs +45 -1
- data/core/nil_class.rbs +98 -35
- data/core/numeric.rbs +22 -32
- data/core/object_space/weak_key_map.rbs +102 -0
- data/core/process.rbs +1242 -655
- data/core/ractor.rbs +139 -120
- data/core/range.rbs +100 -4
- data/core/rational.rbs +0 -4
- data/core/rbs/unnamed/argf.rbs +16 -8
- data/core/rbs/unnamed/env_class.rbs +0 -24
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +1149 -598
- data/core/ruby_vm.rbs +126 -12
- data/core/rubygems/platform.rbs +9 -0
- data/core/rubygems/rubygems.rbs +1 -1
- data/core/rubygems/version.rbs +5 -1
- data/core/set.rbs +20 -22
- data/core/signal.rbs +4 -4
- data/core/string.rbs +283 -230
- data/core/string_io.rbs +2 -14
- data/core/struct.rbs +404 -24
- data/core/symbol.rbs +1 -19
- data/core/thread.rbs +29 -12
- data/core/time.rbs +227 -104
- data/core/trace_point.rbs +2 -5
- data/core/true_class.rbs +54 -21
- data/core/warning.rbs +14 -11
- data/docs/data_and_struct.md +29 -0
- data/docs/syntax.md +3 -5
- data/docs/tools.md +1 -0
- data/ext/rbs_extension/lexer.c +643 -559
- data/ext/rbs_extension/lexer.re +5 -1
- data/ext/rbs_extension/parser.c +12 -3
- data/ext/rbs_extension/unescape.c +7 -47
- data/lib/rbs/cli/diff.rb +4 -1
- data/lib/rbs/cli/validate.rb +280 -0
- data/lib/rbs/cli.rb +2 -194
- data/lib/rbs/collection/config.rb +5 -6
- data/lib/rbs/collection/sources/git.rb +1 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/diff.rb +7 -4
- data/lib/rbs/errors.rb +11 -0
- data/lib/rbs/test/errors.rb +4 -1
- data/lib/rbs/test/guaranteed.rb +2 -3
- data/lib/rbs/test/type_check.rb +15 -10
- data/lib/rbs/test.rb +3 -3
- data/lib/rbs/types.rb +29 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +136 -0
- data/lib/rbs/unit_test/type_assertions.rb +341 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/cli/validate.rbs +43 -0
- data/sig/diff.rbs +3 -1
- data/sig/errors.rbs +8 -0
- data/sig/rbs.rbs +1 -1
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/types.rbs +6 -1
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +28 -0
- data/sig/unit_test/type_assertions.rbs +194 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/stdlib/base64/0/base64.rbs +307 -45
- data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
- data/stdlib/coverage/0/coverage.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +25 -55
- data/stdlib/date/0/date.rbs +1 -43
- data/stdlib/date/0/date_time.rbs +1 -13
- data/stdlib/delegate/0/delegator.rbs +186 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +98 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
- data/stdlib/erb/0/erb.rbs +2 -2
- data/stdlib/fileutils/0/fileutils.rbs +0 -19
- data/stdlib/io-console/0/io-console.rbs +12 -1
- data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
- data/stdlib/json/0/json.rbs +320 -81
- data/stdlib/logger/0/logger.rbs +9 -5
- data/stdlib/monitor/0/monitor.rbs +78 -0
- data/stdlib/net-http/0/net-http.rbs +1880 -543
- data/stdlib/objspace/0/objspace.rbs +19 -13
- data/stdlib/openssl/0/openssl.rbs +508 -127
- data/stdlib/optparse/0/optparse.rbs +25 -11
- data/stdlib/pathname/0/pathname.rbs +1 -1
- data/stdlib/pp/0/pp.rbs +2 -5
- data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
- data/stdlib/pstore/0/pstore.rbs +2 -4
- data/stdlib/rdoc/0/comment.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +4 -2
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/socket/0/unix_socket.rbs +2 -2
- data/stdlib/strscan/0/string_scanner.rbs +3 -2
- data/stdlib/tempfile/0/tempfile.rbs +1 -1
- data/stdlib/uri/0/common.rbs +245 -123
- metadata +23 -4
- data/lib/rbs/test/spy.rb +0 -6
data/core/enumerable.rbs
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
#
|
6
6
|
# * [Querying](rdoc-ref:Enumerable@Methods+for+Querying)
|
7
7
|
# * [Fetching](rdoc-ref:Enumerable@Methods+for+Fetching)
|
8
|
-
# * [Searching
|
8
|
+
# * [Searching and
|
9
|
+
# Filtering](rdoc-ref:Enumerable@Methods+for+Searching+and+Filtering)
|
9
10
|
# * [Sorting](rdoc-ref:Enumerable@Methods+for+Sorting)
|
10
11
|
# * [Iterating](rdoc-ref:Enumerable@Methods+for+Iterating)
|
11
12
|
# * [And more....](rdoc-ref:Enumerable@Other+Methods)
|
@@ -210,6 +211,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
210
211
|
# -->
|
211
212
|
# Returns whether every element meets a given criterion.
|
212
213
|
#
|
214
|
+
# If `self` has no element, returns `true` and argument or block are not used.
|
215
|
+
#
|
213
216
|
# With no argument and no block, returns whether every element is truthy:
|
214
217
|
#
|
215
218
|
# (1..4).all? # => true
|
@@ -252,6 +255,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
252
255
|
# -->
|
253
256
|
# Returns whether any element meets a given criterion.
|
254
257
|
#
|
258
|
+
# If `self` has no element, returns `false` and argument or block are not used.
|
259
|
+
#
|
255
260
|
# With no argument and no block, returns whether any element is truthy:
|
256
261
|
#
|
257
262
|
# (1..4).any? # => true
|
@@ -521,8 +526,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
521
526
|
#
|
522
527
|
# (0..4).to_a # => [0, 1, 2, 3, 4]
|
523
528
|
#
|
524
|
-
# Enumerable#entries is an alias for Enumerable#to_a.
|
525
|
-
#
|
526
529
|
def entries: () -> ::Array[Elem]
|
527
530
|
|
528
531
|
# <!--
|
@@ -721,8 +724,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
721
724
|
# {foo: 0, bar: 1, baz: 2}.include?('foo') # => false
|
722
725
|
# {foo: 0, bar: 1, baz: 2}.include?(0) # => false
|
723
726
|
#
|
724
|
-
# Enumerable#member? is an alias for Enumerable#include?.
|
725
|
-
#
|
726
727
|
def include?: (Elem arg0) -> bool
|
727
728
|
|
728
729
|
# <!--
|
@@ -874,8 +875,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
874
875
|
# "Memo: 3; element: 3"
|
875
876
|
# "Memo: 6; element: 4"
|
876
877
|
#
|
877
|
-
# Enumerable#reduce is an alias for Enumerable#inject.
|
878
|
-
#
|
879
878
|
def inject: (untyped init, Symbol method) -> untyped
|
880
879
|
| (Symbol method) -> untyped
|
881
880
|
| [A] (A initial) { (A, Elem) -> A } -> A
|
@@ -1446,8 +1445,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
1446
1445
|
|
1447
1446
|
# <!--
|
1448
1447
|
# rdoc-file=enum.c
|
1449
|
-
# - to_h -> hash
|
1450
|
-
# - to_h {|element| ... } -> hash
|
1448
|
+
# - to_h(*args) -> hash
|
1449
|
+
# - to_h(*args) {|element| ... } -> hash
|
1451
1450
|
# -->
|
1452
1451
|
# When `self` consists of 2-element arrays, returns a hash each of whose entries
|
1453
1452
|
# is the key-value pair formed from one of those arrays:
|
@@ -1570,8 +1569,6 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
1570
1569
|
# {foo: 0, bar: 1, baz: 2}.include?('foo') # => false
|
1571
1570
|
# {foo: 0, bar: 1, baz: 2}.include?(0) # => false
|
1572
1571
|
#
|
1573
|
-
# Enumerable#member? is an alias for Enumerable#include?.
|
1574
|
-
#
|
1575
1572
|
def member?: (Elem arg0) -> bool
|
1576
1573
|
|
1577
1574
|
# <!-- rdoc-file=enum.c -->
|
@@ -1717,20 +1714,16 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
1717
1714
|
# "Memo: 3; element: 3"
|
1718
1715
|
# "Memo: 6; element: 4"
|
1719
1716
|
#
|
1720
|
-
# Enumerable#reduce is an alias for Enumerable#inject.
|
1721
|
-
#
|
1722
1717
|
alias reduce inject
|
1723
1718
|
|
1724
1719
|
# <!--
|
1725
1720
|
# rdoc-file=enum.c
|
1726
|
-
# - to_a -> array
|
1721
|
+
# - to_a(*args) -> array
|
1727
1722
|
# -->
|
1728
1723
|
# Returns an array containing the items in `self`:
|
1729
1724
|
#
|
1730
1725
|
# (0..4).to_a # => [0, 1, 2, 3, 4]
|
1731
1726
|
#
|
1732
|
-
# Enumerable#entries is an alias for Enumerable#to_a.
|
1733
|
-
#
|
1734
1727
|
def to_a: () -> ::Array[Elem]
|
1735
1728
|
|
1736
1729
|
# <!--
|
@@ -1774,8 +1767,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
1774
1767
|
# %w[a b c c b a a b c].uniq # => ["a", "b", "c"]
|
1775
1768
|
# [0, 1, 2, 2, 1, 0, 0, 1, 2].uniq # => [0, 1, 2]
|
1776
1769
|
#
|
1777
|
-
# With a block, returns a new array containing only for which the block
|
1778
|
-
# a unique value:
|
1770
|
+
# With a block, returns a new array containing elements only for which the block
|
1771
|
+
# returns a unique value:
|
1779
1772
|
#
|
1780
1773
|
# a = [0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]
|
1781
1774
|
# a.uniq {|i| i.even? ? i : 0 } # => [0, 2, 4]
|
data/core/enumerator.rbs
CHANGED
@@ -37,10 +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
42
|
#
|
43
|
-
#
|
43
|
+
# ## External Iteration
|
44
44
|
#
|
45
45
|
# An Enumerator can also be used as an external iterator. For example,
|
46
46
|
# Enumerator#next returns the next value of the iterator or raises StopIteration
|
@@ -52,42 +52,48 @@
|
|
52
52
|
# puts e.next # => 3
|
53
53
|
# puts e.next # raises StopIteration
|
54
54
|
#
|
55
|
-
# `next`, `next_values`, `peek
|
56
|
-
# external iteration (and Array#zip(Enumerable-not-Array) which uses `next`
|
55
|
+
# `next`, `next_values`, `peek`, and `peek_values` are the only methods which
|
56
|
+
# use external iteration (and Array#zip(Enumerable-not-Array) which uses `next`
|
57
|
+
# internally).
|
57
58
|
#
|
58
59
|
# These methods do not affect other internal enumeration methods, unless the
|
59
60
|
# underlying iteration method itself has side-effect, e.g. IO#each_line.
|
60
61
|
#
|
62
|
+
# FrozenError will be raised if these methods are called against a frozen
|
63
|
+
# enumerator. Since `rewind` and `feed` also change state for external
|
64
|
+
# iteration, these methods may raise FrozenError too.
|
65
|
+
#
|
61
66
|
# External iteration differs **significantly** from internal iteration due to
|
62
67
|
# using a Fiber:
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
68
|
+
# * The Fiber adds some overhead compared to internal enumeration.
|
69
|
+
# * The stacktrace will only include the stack from the Enumerator, not above.
|
70
|
+
# * Fiber-local variables are **not** inherited inside the Enumerator Fiber,
|
71
|
+
# which instead starts with no Fiber-local variables.
|
72
|
+
# * Fiber storage variables **are** inherited and are designed to handle
|
73
|
+
# Enumerator Fibers. Assigning to a Fiber storage variable only affects the
|
74
|
+
# current Fiber, so if you want to change state in the caller Fiber of the
|
75
|
+
# Enumerator Fiber, you need to use an extra indirection (e.g., use some
|
76
|
+
# object in the Fiber storage variable and mutate some ivar of it).
|
77
|
+
#
|
73
78
|
#
|
74
79
|
# Concretely:
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
80
|
+
#
|
81
|
+
# Thread.current[:fiber_local] = 1
|
82
|
+
# Fiber[:storage_var] = 1
|
83
|
+
# e = Enumerator.new do |y|
|
84
|
+
# p Thread.current[:fiber_local] # for external iteration: nil, for internal iteration: 1
|
85
|
+
# p Fiber[:storage_var] # => 1, inherited
|
86
|
+
# Fiber[:storage_var] += 1
|
87
|
+
# y << 42
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# p e.next # => 42
|
91
|
+
# p Fiber[:storage_var] # => 1 (it ran in a different Fiber)
|
92
|
+
#
|
93
|
+
# e.each { p _1 }
|
94
|
+
# p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber)
|
95
|
+
#
|
96
|
+
# ## Convert External Iteration to Internal Iteration
|
91
97
|
#
|
92
98
|
# You can use an external iterator to implement an internal iterator as follows:
|
93
99
|
#
|
data/core/errors.rbs
CHANGED
@@ -188,6 +188,10 @@ end
|
|
188
188
|
#
|
189
189
|
# LoadError: no such file to load -- this/file/does/not/exist
|
190
190
|
#
|
191
|
+
# <!-- rdoc-file=lib/bundled_gems.rb -->
|
192
|
+
# for RubyGems without Bundler environment. If loading library is not part of
|
193
|
+
# the default gems and the bundled gems, warn it.
|
194
|
+
#
|
191
195
|
class LoadError < ScriptError
|
192
196
|
# <!-- rdoc-file=error.c -->
|
193
197
|
# the path failed to load
|
data/core/false_class.rbs
CHANGED
@@ -8,32 +8,47 @@ class FalseClass
|
|
8
8
|
|
9
9
|
# <!--
|
10
10
|
# rdoc-file=object.c
|
11
|
-
# - false &
|
12
|
-
# - nil &
|
11
|
+
# - false & object -> false
|
12
|
+
# - nil & object -> false
|
13
13
|
# -->
|
14
|
-
#
|
15
|
-
#
|
14
|
+
# Returns `false`:
|
15
|
+
#
|
16
|
+
# false & true # => false
|
17
|
+
# false & Object.new # => false
|
18
|
+
#
|
19
|
+
# Argument `object` is evaluated:
|
20
|
+
#
|
21
|
+
# false & raise # Raises RuntimeError.
|
16
22
|
#
|
17
23
|
def &: (untyped obj) -> false
|
18
24
|
|
19
25
|
# <!--
|
20
26
|
# rdoc-file=object.c
|
21
|
-
# -
|
27
|
+
# - true === other -> true or false
|
28
|
+
# - false === other -> true or false
|
29
|
+
# - nil === other -> true or false
|
22
30
|
# -->
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
31
|
+
# Returns `true` or `false`.
|
32
|
+
#
|
33
|
+
# Like Object#==, if `object` is an instance of Object (and not an instance of
|
34
|
+
# one of its many subclasses).
|
35
|
+
#
|
36
|
+
# This method is commonly overridden by those subclasses, to provide meaningful
|
37
|
+
# semantics in `case` statements.
|
26
38
|
#
|
27
39
|
def ===: (false) -> true
|
28
40
|
| (untyped obj) -> bool
|
29
41
|
|
30
42
|
# <!--
|
31
43
|
# rdoc-file=object.c
|
32
|
-
# - false ^
|
33
|
-
# - nil
|
44
|
+
# - false ^ object -> true or false
|
45
|
+
# - nil ^ object -> true or false
|
34
46
|
# -->
|
35
|
-
#
|
36
|
-
#
|
47
|
+
# Returns `false` if `object` is `nil` or `false`, `true` otherwise:
|
48
|
+
#
|
49
|
+
# nil ^ nil # => false
|
50
|
+
# nil ^ false # => false
|
51
|
+
# nil ^ Object.new # => true
|
37
52
|
#
|
38
53
|
def ^: (false | nil) -> false
|
39
54
|
| (untyped obj) -> bool
|
@@ -53,10 +68,14 @@ class FalseClass
|
|
53
68
|
|
54
69
|
# <!--
|
55
70
|
# rdoc-file=object.c
|
56
|
-
# - false |
|
57
|
-
# - nil |
|
71
|
+
# - false | object -> true or false
|
72
|
+
# - nil | object -> true or false
|
58
73
|
# -->
|
59
|
-
#
|
74
|
+
# Returns `false` if `object` is `nil` or `false`, `true` otherwise:
|
75
|
+
#
|
76
|
+
# nil | nil # => false
|
77
|
+
# nil | false # => false
|
78
|
+
# nil | Object.new # => true
|
60
79
|
#
|
61
80
|
def |: (nil | false) -> false
|
62
81
|
| (untyped obj) -> bool
|
data/core/fiber.rbs
CHANGED
@@ -369,6 +369,27 @@ class Fiber < Object
|
|
369
369
|
#
|
370
370
|
alias inspect to_s
|
371
371
|
|
372
|
+
# <!--
|
373
|
+
# rdoc-file=cont.c
|
374
|
+
# - fiber.kill -> nil
|
375
|
+
# -->
|
376
|
+
# Terminates the fiber by raising an uncatchable exception. It only terminates
|
377
|
+
# the given fiber and no other fiber, returning `nil` to another fiber if that
|
378
|
+
# fiber was calling #resume or #transfer.
|
379
|
+
#
|
380
|
+
# `Fiber#kill` only interrupts another fiber when it is in Fiber.yield. If
|
381
|
+
# called on the current fiber then it raises that exception at the `Fiber#kill`
|
382
|
+
# call site.
|
383
|
+
#
|
384
|
+
# If the fiber has not been started, transition directly to the terminated
|
385
|
+
# state.
|
386
|
+
#
|
387
|
+
# If the fiber is already terminated, does nothing.
|
388
|
+
#
|
389
|
+
# Raises FiberError if called on a fiber belonging to another thread.
|
390
|
+
#
|
391
|
+
def kill: () -> nil
|
392
|
+
|
372
393
|
# <!--
|
373
394
|
# rdoc-file=cont.c
|
374
395
|
# - fiber.raise -> obj
|
@@ -389,6 +410,8 @@ class Fiber < Object
|
|
389
410
|
# parameter is an array of callback information. Exceptions are caught by the
|
390
411
|
# `rescue` clause of `begin...end` blocks.
|
391
412
|
#
|
413
|
+
# Raises `FiberError` if called on a Fiber belonging to another `Thread`.
|
414
|
+
#
|
392
415
|
def raise: (?string msg) -> untyped
|
393
416
|
| (_Exception, ?string msg, ?Array[string] backtrace) -> untyped
|
394
417
|
|