rbs 3.3.2 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +65 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/README.md +1 -0
- data/Rakefile +2 -2
- 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 +54 -121
- 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/gem.md +58 -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 +10 -2
- 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/minitest/0/minitest/test/lifecycle_hooks.rbs +6 -6
- 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 +24 -4
- data/lib/rbs/test/spy.rb +0 -6
data/core/trace_point.rbs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
# <!-- rdoc-file=trace_point.rb -->
|
|
2
|
-
# Document-class: TracePoint
|
|
3
|
-
#
|
|
4
2
|
# A class that provides the functionality of Kernel#set_trace_func in a nice
|
|
5
3
|
# Object-Oriented API.
|
|
6
4
|
#
|
|
@@ -207,9 +205,8 @@ class TracePoint < Object
|
|
|
207
205
|
# -->
|
|
208
206
|
# Return the generated binding object from event.
|
|
209
207
|
#
|
|
210
|
-
# Note that for `c_call` and `c_return` events, the
|
|
211
|
-
#
|
|
212
|
-
# themselves do not have bindings.
|
|
208
|
+
# Note that for `c_call` and `c_return` events, the method will return `nil`,
|
|
209
|
+
# since C methods themselves do not have bindings.
|
|
213
210
|
#
|
|
214
211
|
def binding: () -> Binding?
|
|
215
212
|
|
data/core/true_class.rbs
CHANGED
|
@@ -1,66 +1,99 @@
|
|
|
1
1
|
# <!-- rdoc-file=object.c -->
|
|
2
|
-
# The
|
|
3
|
-
#
|
|
4
|
-
#
|
|
2
|
+
# The class of the singleton object `true`.
|
|
3
|
+
#
|
|
4
|
+
# Several of its methods act as operators:
|
|
5
|
+
#
|
|
6
|
+
# * #&
|
|
7
|
+
# * #|
|
|
8
|
+
# * #===
|
|
9
|
+
# * #^
|
|
10
|
+
#
|
|
11
|
+
#
|
|
12
|
+
# One other method:
|
|
13
|
+
#
|
|
14
|
+
# * #to_s and its alias #inspect.
|
|
5
15
|
#
|
|
6
16
|
class TrueClass
|
|
7
17
|
def !: () -> false
|
|
8
18
|
|
|
9
19
|
# <!--
|
|
10
20
|
# rdoc-file=object.c
|
|
11
|
-
# - true &
|
|
21
|
+
# - true & object -> true or false
|
|
12
22
|
# -->
|
|
13
|
-
#
|
|
23
|
+
# Returns `false` if `object` is `false` or `nil`, `true` otherwise:
|
|
24
|
+
#
|
|
25
|
+
# true & Object.new # => true true & false # => false true & nil #
|
|
26
|
+
# => false
|
|
14
27
|
#
|
|
15
28
|
def &: (false | nil) -> false
|
|
16
29
|
| (untyped obj) -> bool
|
|
17
30
|
|
|
18
31
|
# <!--
|
|
19
32
|
# rdoc-file=object.c
|
|
20
|
-
# -
|
|
33
|
+
# - true === other -> true or false
|
|
34
|
+
# - false === other -> true or false
|
|
35
|
+
# - nil === other -> true or false
|
|
21
36
|
# -->
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
37
|
+
# Returns `true` or `false`.
|
|
38
|
+
#
|
|
39
|
+
# Like Object#==, if `object` is an instance of Object (and not an instance of
|
|
40
|
+
# one of its many subclasses).
|
|
41
|
+
#
|
|
42
|
+
# This method is commonly overridden by those subclasses, to provide meaningful
|
|
43
|
+
# semantics in `case` statements.
|
|
25
44
|
#
|
|
26
45
|
def ===: (true) -> true
|
|
27
46
|
| (untyped obj) -> bool
|
|
28
47
|
|
|
29
48
|
# <!--
|
|
30
49
|
# rdoc-file=object.c
|
|
31
|
-
# - true ^
|
|
50
|
+
# - true ^ object -> !object
|
|
32
51
|
# -->
|
|
33
|
-
#
|
|
52
|
+
# Returns `true` if `object` is `false` or `nil`, `false` otherwise:
|
|
53
|
+
#
|
|
54
|
+
# true ^ Object.new # => false
|
|
55
|
+
# true ^ false # => true
|
|
56
|
+
# true ^ nil # => true
|
|
34
57
|
#
|
|
35
58
|
def ^: (false | nil) -> true
|
|
36
59
|
| (untyped obj) -> bool
|
|
37
60
|
|
|
38
61
|
# <!-- rdoc-file=object.c -->
|
|
39
|
-
#
|
|
62
|
+
# Returns string `'true'`:
|
|
63
|
+
#
|
|
64
|
+
# true.to_s # => "true"
|
|
65
|
+
#
|
|
66
|
+
# TrueClass#inspect is an alias for TrueClass#to_s.
|
|
40
67
|
#
|
|
41
68
|
alias inspect to_s
|
|
42
69
|
|
|
43
70
|
# <!--
|
|
44
71
|
# rdoc-file=object.c
|
|
45
|
-
# - true.to_s
|
|
72
|
+
# - true.to_s -> 'true'
|
|
46
73
|
# -->
|
|
47
|
-
#
|
|
74
|
+
# Returns string `'true'`:
|
|
75
|
+
#
|
|
76
|
+
# true.to_s # => "true"
|
|
77
|
+
#
|
|
78
|
+
# TrueClass#inspect is an alias for TrueClass#to_s.
|
|
48
79
|
#
|
|
49
80
|
def to_s: () -> "true"
|
|
50
81
|
|
|
51
82
|
# <!--
|
|
52
83
|
# rdoc-file=object.c
|
|
53
|
-
# - true |
|
|
84
|
+
# - true | object -> true
|
|
54
85
|
# -->
|
|
55
|
-
#
|
|
56
|
-
# evaluated; there is no short-circuit evaluation in this case.
|
|
86
|
+
# Returns `true`:
|
|
57
87
|
#
|
|
58
|
-
# true |
|
|
59
|
-
# true
|
|
88
|
+
# true | Object.new # => true
|
|
89
|
+
# true | false # => true
|
|
90
|
+
# true | nil # => true
|
|
60
91
|
#
|
|
61
|
-
#
|
|
92
|
+
# Argument `object` is evaluated. This is different from `true` with the
|
|
93
|
+
# short-circuit operator, whose operand is evaluated only if necessary:
|
|
62
94
|
#
|
|
63
|
-
#
|
|
95
|
+
# true | raise # => Raises RuntimeError.
|
|
96
|
+
# true || raise # => true
|
|
64
97
|
#
|
|
65
98
|
def |: (untyped obj) -> true
|
|
66
99
|
end
|
data/core/warning.rbs
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
#
|
|
6
6
|
# Changing the behavior of Warning.warn is useful to customize how warnings are
|
|
7
7
|
# handled by Ruby, for instance by filtering some warnings, and/or outputting
|
|
8
|
-
# warnings somewhere other than
|
|
8
|
+
# warnings somewhere other than `$stderr`.
|
|
9
9
|
#
|
|
10
10
|
# If you want to change the behavior of Warning.warn you should use
|
|
11
|
-
#
|
|
12
|
-
# default behavior of printing the warning to
|
|
11
|
+
# `Warning.extend(MyNewModuleWithWarnMethod)` and you can use `super` to get the
|
|
12
|
+
# default behavior of printing the warning to `$stderr`.
|
|
13
13
|
#
|
|
14
14
|
# Example:
|
|
15
15
|
# module MyWarningFilter
|
|
@@ -26,12 +26,13 @@
|
|
|
26
26
|
# You should never redefine Warning#warn (the instance method), as that will
|
|
27
27
|
# then no longer provide a way to use the default behavior.
|
|
28
28
|
#
|
|
29
|
-
# The
|
|
29
|
+
# The [warning](https://rubygems.org/gems/warning) gem provides convenient ways
|
|
30
|
+
# to customize Warning.warn.
|
|
30
31
|
#
|
|
31
32
|
module Warning
|
|
32
33
|
# The types of categories the `Warning` module understands.
|
|
33
34
|
#
|
|
34
|
-
type category = :deprecated | :experimental
|
|
35
|
+
type category = :deprecated | :experimental | :performance
|
|
35
36
|
|
|
36
37
|
# <!--
|
|
37
38
|
# rdoc-file=error.c
|
|
@@ -42,17 +43,19 @@ module Warning
|
|
|
42
43
|
#
|
|
43
44
|
# `:deprecated`
|
|
44
45
|
# : deprecation warnings
|
|
46
|
+
# * assignment of non-nil value to `$,` and `$;`
|
|
47
|
+
# * keyword arguments
|
|
45
48
|
#
|
|
46
|
-
#
|
|
47
|
-
# * keyword arguments
|
|
48
|
-
# * proc/lambda without block
|
|
49
|
-
#
|
|
50
|
-
# etc.
|
|
49
|
+
# etc.
|
|
51
50
|
#
|
|
52
51
|
# `:experimental`
|
|
53
52
|
# : experimental features
|
|
53
|
+
# * Pattern matching
|
|
54
|
+
#
|
|
54
55
|
#
|
|
55
|
-
#
|
|
56
|
+
# `:performance`
|
|
57
|
+
# : performance hints
|
|
58
|
+
# * Shape variation limit
|
|
56
59
|
#
|
|
57
60
|
def self.[]: (category) -> bool
|
|
58
61
|
|
data/docs/data_and_struct.md
CHANGED
|
@@ -55,3 +55,32 @@ Measure.ancestors #=> [Measure, #<Class:0xOOF>, Data, ...]
|
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
[^1]: [Shannon Skipper](https://github.com/havenwood) told me it in Discord
|
|
58
|
+
|
|
59
|
+
## Generate prototype for `Data` and `Struct`
|
|
60
|
+
|
|
61
|
+
RBS prototypes for classes using `Data` and `Struct` can be generated by `rbs prototype runtime`.
|
|
62
|
+
|
|
63
|
+
```rb
|
|
64
|
+
# t.rb
|
|
65
|
+
class Measure < Data.define(:amount, :unit)
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
$ bundle exec rbs prototype runtime -R t.rb Measure
|
|
71
|
+
class Measure < ::Data
|
|
72
|
+
def self.new: (untyped amount, untyped unit) -> instance
|
|
73
|
+
| (amount: untyped, unit: untyped) -> instance
|
|
74
|
+
|
|
75
|
+
def self.[]: (untyped amount, untyped unit) -> instance
|
|
76
|
+
| (amount: untyped, unit: untyped) -> instance
|
|
77
|
+
|
|
78
|
+
def self.members: () -> [ :amount, :unit ]
|
|
79
|
+
|
|
80
|
+
def members: () -> [ :amount, :unit ]
|
|
81
|
+
|
|
82
|
+
attr_reader amount: untyped
|
|
83
|
+
|
|
84
|
+
attr_reader unit: untyped
|
|
85
|
+
end
|
|
86
|
+
```
|
data/docs/gem.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Releasing a gem with RBS
|
|
2
|
+
|
|
3
|
+
You can release the RBS type definition of your gem included in the gem package. Just add your RBS files inside `/sig` directory, put them in your rubygem package, and release a new version. RBS gem will load the RBS files from your gem package automatically.
|
|
4
|
+
|
|
5
|
+
## `/sig` directory
|
|
6
|
+
|
|
7
|
+
RBS gem tries to load a type definition of a gem from gem package first. It checks if there is `/sig` directory in the gem package and loads `*.rbs` files from the directory. So, everything you have to do to make your type definition available are:
|
|
8
|
+
|
|
9
|
+
1. Add `/sig` directory in your gem package
|
|
10
|
+
2. Put your RBS files inside the directory
|
|
11
|
+
3. Make sure the RBS files are included in the gem package
|
|
12
|
+
|
|
13
|
+
### Hidden RBS files
|
|
14
|
+
|
|
15
|
+
If you have RBS files you don't want to export to the gem users, you can put the files under a directory that starts with `_``.
|
|
16
|
+
|
|
17
|
+
Assume you have three RBS files in your gem package:
|
|
18
|
+
|
|
19
|
+
* `/sig/foo.rbs`
|
|
20
|
+
* `/sig/bar/baz.rbs`
|
|
21
|
+
* `/sig/_private/internal.rbs`
|
|
22
|
+
|
|
23
|
+
`foo.rbs` and `baz.rbs` will be loaded from the gem package, but the `internal.rbs` will be skipped. This is only when you load RBS files of a *library*, for example through `-r` option given to `rbs` command. If you load RBS files as *source code*, for example through `-I` option given to `rbs` command, the hidden RBS files will be loaded too.
|
|
24
|
+
|
|
25
|
+
* `rbs -r your-gem` => Loading a library
|
|
26
|
+
* `rbs -I sig` => Loading RBS files as source code
|
|
27
|
+
|
|
28
|
+
### Adding `manifest.yaml`
|
|
29
|
+
|
|
30
|
+
`manifest.yaml` lets you declare dependencies to standard libraries. Here is an example, from [RBS gem](https://github.com/ruby/rbs/blob/6b3d0f976a50b3974d0bff26ea8fa9931053f38b/sig/manifest.yaml).
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
dependencies:
|
|
34
|
+
- name: abbrev
|
|
35
|
+
- name: json
|
|
36
|
+
- name: logger
|
|
37
|
+
- name: optparse
|
|
38
|
+
- name: pathname
|
|
39
|
+
- name: rdoc
|
|
40
|
+
- name: tsort
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Note that you don't have to write the dependencies that are included in your `.gemspec`. RBS will detect the dependencies between gems, declared in `.gemspec`. `manifest.yaml` is a material for undeclared dependencies, which usually is for standard libraries.
|
|
44
|
+
|
|
45
|
+
## Testing your type definition
|
|
46
|
+
|
|
47
|
+
If you develop your gem using a static type checker, like [Steep](https://github.com/soutaro/steep), your type definition will be (mostly) correct and reliable. If not, we strongly recommend adding extra tests focusing on the RBS type definitions.
|
|
48
|
+
|
|
49
|
+
`RBS::UnitTest` is a library to do that. `assert_send_type` is the most important assertion.
|
|
50
|
+
|
|
51
|
+
```rb
|
|
52
|
+
assert_send_type '(Regexp) { (String) -> String } -> String',
|
|
53
|
+
'hello', :gsub, /hello/, &proc { "foo" }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
It calls `String#gsub` method and confirms if given arguments and the return value has correct types.
|
|
57
|
+
|
|
58
|
+
You can find examples under `test/stdlib` directory of [RBS repository](https://github.com/ruby/rbs/blob/6b3d0f976a50b3974d0bff26ea8fa9931053f38b/test/stdlib/String_test.rb).
|
data/docs/syntax.md
CHANGED
|
@@ -44,7 +44,7 @@ _literal_ ::= _string-literal_
|
|
|
44
44
|
| `true`
|
|
45
45
|
| `false`
|
|
46
46
|
|
|
47
|
-
_proc_ ::= _parameters?_ _self-type-binding?_ _block?_ `->` _type_
|
|
47
|
+
_proc_ ::= `^` _parameters?_ _self-type-binding?_ _block?_ `->` _type_
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
### Class instance type
|
|
@@ -311,8 +311,6 @@ end
|
|
|
311
311
|
```markdown
|
|
312
312
|
_method-type_ ::= _parameters?_ _block?_ `->` _type_ # Method type
|
|
313
313
|
|
|
314
|
-
_proc_ ::= `^` _parameters?_ _self-type-binding?_ _block?_ `->` _type_ # Proc type
|
|
315
|
-
|
|
316
314
|
_parameters?_ ::= (Empty)
|
|
317
315
|
| _parameters_ (Parameters)
|
|
318
316
|
|
|
@@ -435,8 +433,8 @@ _visibility-member_ ::= _visibility_
|
|
|
435
433
|
|
|
436
434
|
_ivar-name_ ::= /@\w+/
|
|
437
435
|
_cvar-name_ ::= /@@\w+/
|
|
438
|
-
_method-name_ ::=
|
|
439
|
-
| /`[^`]+`/
|
|
436
|
+
_method-name_ ::= _most of the possible ruby method names_
|
|
437
|
+
| /`[^`]+`/ # Quoted method names
|
|
440
438
|
```
|
|
441
439
|
|
|
442
440
|
### Ivar definition
|
data/docs/tools.md
CHANGED
|
@@ -14,3 +14,4 @@ This documentation describes major tools related to RBS. They are listed alphabe
|
|
|
14
14
|
* Sublime Text: [sublime-rbs-plugin](https://github.com/soutaro/sublime-rbs-plugin)
|
|
15
15
|
* Vim: [rbs.vim](https://github.com/pocke/rbs.vim)
|
|
16
16
|
* Visual Studio Code: [vscode-rbs-syntax](https://github.com/soutaro/vscode-rbs-syntax)
|
|
17
|
+
* NeoVim: [tree-sitter-rbs](https://github.com/joker1007/tree-sitter-rbs)
|