rbs 4.2.0 → 4.2.1.pre.1
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/CHANGELOG.md +15 -0
- data/docs/collection.md +33 -11
- data/docs/data_and_struct.md +1 -1
- data/lib/rbs/cli.rb +54 -8
- data/lib/rbs/prototype/runtime/value_object_generator.rb +8 -17
- data/lib/rbs/version.rb +1 -1
- data/sig/cli.rbs +6 -0
- data/sig/prototype/runtime.rbs +0 -2
- data/sig/shims/bundler.rbs +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f1e581488613321c155d44ece6ce189d985fb3dac67c4dc10b61b3f71e7420b
|
|
4
|
+
data.tar.gz: b33c3d43cbd6f46a0995aea52d72fdc6041ce48b4d649f2401a1e7b5d1abd090
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86d91c1baecfd5ad59f46c07af82d8d8bf1fabb33473d74484d547db179b3060430f495d6f1dbe65ee8465365be4cd5bd6c08526435ccc5c01677ad7cf7096df
|
|
7
|
+
data.tar.gz: b4ef431b1b7094f2c6734b54ad6884af9dd4d56a5127831556af8e36a6eb54064621d5e2b5557f44d1eec0f605a3b934b48a7b28815043c2abb6c36b79b5ea0c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 4.2.1.pre.1 (2026-08-26)
|
|
4
|
+
|
|
5
|
+
### Library changes
|
|
6
|
+
|
|
7
|
+
* Remove some obsolete ruby version guards ([#3100](https://github.com/ruby/rbs/pull/3100))
|
|
8
|
+
|
|
9
|
+
#### rbs collection
|
|
10
|
+
|
|
11
|
+
* Make `rbs collection` say where the gem list comes from ([#3094](https://github.com/ruby/rbs/pull/3094))
|
|
12
|
+
|
|
13
|
+
### Miscellaneous
|
|
14
|
+
|
|
15
|
+
* Run `bundle` with the Ruby running the tests ([#3099](https://github.com/ruby/rbs/pull/3099))
|
|
16
|
+
* docs: fix typo prefered -> preferred ([#3098](https://github.com/ruby/rbs/pull/3098))
|
|
17
|
+
|
|
3
18
|
## 4.2.0 (2026-08-23)
|
|
4
19
|
|
|
5
20
|
RBS 4.2 accepts non-ASCII characters in identifiers. Method names, instance variable names and parameter names can be written in any script, and other names may contain non-ASCII characters as long as they start with an ASCII letter, which is what tells a constant from a method name.
|
data/docs/collection.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
`rbs collection` sub command manages third party gems' RBS. In short, it is `bundler` for RBS.
|
|
4
4
|
|
|
5
|
+
## Quickstart
|
|
6
|
+
|
|
7
|
+
In a project that has a `Gemfile.lock`:
|
|
8
|
+
|
|
9
|
+
```console
|
|
10
|
+
$ rbs collection init
|
|
11
|
+
$ rbs collection install
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`rbs collection` reads `Gemfile.lock`, so there is no list of dependencies to maintain. `rbs` and type checkers such as Steep load the installed RBS files automatically.
|
|
15
|
+
|
|
5
16
|
## Requirements
|
|
6
17
|
|
|
7
18
|
* `git(1)`
|
|
@@ -17,33 +28,44 @@ First, generate the configuration file, `rbs_collection.yaml`, with `rbs collect
|
|
|
17
28
|
$ rbs collection init
|
|
18
29
|
created: rbs_collection.yaml
|
|
19
30
|
|
|
31
|
+
rbs collection installs RBS files for the gems in your Gemfile.lock.
|
|
32
|
+
Gems in Gemfile.lock don't need to be listed anywhere.
|
|
33
|
+
|
|
34
|
+
Next steps:
|
|
35
|
+
$ echo "/.gem_rbs_collection/" >> .gitignore
|
|
36
|
+
$ rbs collection install # writes rbs_collection.lock.yaml; keep it in version control
|
|
37
|
+
|
|
20
38
|
$ cat rbs_collection.yaml
|
|
39
|
+
# rbs collection installs RBS files for the gems in your Gemfile.lock.
|
|
40
|
+
# Run `rbs collection install` to resolve them into rbs_collection.lock.yaml and install them.
|
|
41
|
+
|
|
21
42
|
# Download sources
|
|
22
43
|
sources:
|
|
23
|
-
-
|
|
44
|
+
- type: git
|
|
45
|
+
name: ruby/gem_rbs_collection
|
|
24
46
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
25
47
|
revision: main
|
|
26
48
|
repo_dir: gems
|
|
27
49
|
|
|
50
|
+
# You can specify local directories as sources also.
|
|
51
|
+
# - type: local
|
|
52
|
+
# path: path/to/your/local/repository
|
|
53
|
+
|
|
28
54
|
# A directory to install the downloaded RBSs
|
|
29
55
|
path: .gem_rbs_collection
|
|
30
56
|
|
|
31
57
|
# gems:
|
|
58
|
+
# # RBS for a library that doesn't appear in Gemfile.lock, such as a non-gem standard library.
|
|
59
|
+
# - name: socket
|
|
60
|
+
#
|
|
32
61
|
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
|
33
62
|
# - name: GEM_NAME
|
|
34
63
|
# ignore: true
|
|
35
64
|
```
|
|
36
65
|
|
|
37
|
-
I also recommend updating `.gitignore`.
|
|
38
|
-
|
|
39
|
-
```console
|
|
40
|
-
$ echo /.gem_rbs_collection/ >> .gitignore
|
|
41
|
-
```
|
|
42
|
-
|
|
43
66
|
### Install dependencies
|
|
44
67
|
|
|
45
68
|
Then, install gems' RBS with `rbs collection install`! It copies RBS from [the gem RBS repository](https://github.com/ruby/gem_rbs_collection) to `.gem_rbs_collection/` directory by default.
|
|
46
|
-
I recommend to ignore `.gem_rbs_collection/` from version control system, such as Git.
|
|
47
69
|
|
|
48
70
|
```console
|
|
49
71
|
$ rbs collection install
|
|
@@ -86,9 +108,9 @@ sources:
|
|
|
86
108
|
path: .gem_rbs_collection
|
|
87
109
|
|
|
88
110
|
gems:
|
|
89
|
-
# If the Gemfile.lock doesn't contain
|
|
90
|
-
# you can write the
|
|
91
|
-
- name:
|
|
111
|
+
# If the Gemfile.lock doesn't contain socket but you use it,
|
|
112
|
+
# you can write the library name explicitly to install RBS of the library.
|
|
113
|
+
- name: socket
|
|
92
114
|
|
|
93
115
|
# If the Gemfile.lock contains nokogiri gem but you don't want to use the RBS,
|
|
94
116
|
# you can ignore the gem.
|
data/docs/data_and_struct.md
CHANGED
|
@@ -48,7 +48,7 @@ class Measure < Data.define(:amount, :unit)
|
|
|
48
48
|
end
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
@soutaro has
|
|
51
|
+
@soutaro has preferred inheriting from `Data.define`, but you may find an extra annonymous class in `.ancestors` [^1].
|
|
52
52
|
|
|
53
53
|
```ruby
|
|
54
54
|
Measure.ancestors #=> [Measure, #<Class:0xOOF>, Data, ...]
|
data/lib/rbs/cli.rb
CHANGED
|
@@ -1089,21 +1089,37 @@ EOB
|
|
|
1089
1089
|
|
|
1090
1090
|
case args[0]
|
|
1091
1091
|
when 'install', 'instal', 'insta', 'inst', 'ins', 'in', 'i'
|
|
1092
|
-
|
|
1093
|
-
|
|
1092
|
+
if params[:frozen]
|
|
1093
|
+
unless lock_path.exist?
|
|
1094
|
+
if config_path.exist?
|
|
1095
|
+
stderr.puts "#{lock_path} not found. Run `rbs collection install` without `--frozen` to generate it."
|
|
1096
|
+
else
|
|
1097
|
+
stderr.puts "#{lock_path} not found. Run `rbs collection init` and `rbs collection install` to generate it."
|
|
1098
|
+
end
|
|
1099
|
+
return 1
|
|
1100
|
+
end
|
|
1101
|
+
else
|
|
1102
|
+
return 1 unless collection_config_available?(config_path)
|
|
1103
|
+
definition = bundler_definition or return 1
|
|
1104
|
+
Collection::Config.generate_lockfile(config_path: config_path, definition: definition)
|
|
1094
1105
|
end
|
|
1095
1106
|
Collection::Installer.new(lockfile_path: lock_path, stdout: stdout).install_from_lockfile
|
|
1096
1107
|
when 'update', 'updat', 'upda', 'upd', 'up', 'u'
|
|
1108
|
+
return 1 unless collection_config_available?(config_path)
|
|
1109
|
+
definition = bundler_definition or return 1
|
|
1097
1110
|
# TODO: Be aware of argv to update only specified gem
|
|
1098
|
-
Collection::Config.generate_lockfile(config_path: config_path, definition:
|
|
1111
|
+
Collection::Config.generate_lockfile(config_path: config_path, definition: definition, with_lockfile: false)
|
|
1099
1112
|
Collection::Installer.new(lockfile_path: lock_path, stdout: stdout).install_from_lockfile
|
|
1100
1113
|
when 'init'
|
|
1101
1114
|
if config_path.exist?
|
|
1102
|
-
puts "#{config_path} already exists"
|
|
1115
|
+
stderr.puts "#{config_path} already exists"
|
|
1103
1116
|
return 1
|
|
1104
1117
|
end
|
|
1105
1118
|
|
|
1106
1119
|
config_path.write(<<~'YAML')
|
|
1120
|
+
# rbs collection installs RBS files for the gems in your Gemfile.lock.
|
|
1121
|
+
# Run `rbs collection install` to resolve them into rbs_collection.lock.yaml and install them.
|
|
1122
|
+
|
|
1107
1123
|
# Download sources
|
|
1108
1124
|
sources:
|
|
1109
1125
|
- type: git
|
|
@@ -1120,27 +1136,57 @@ EOB
|
|
|
1120
1136
|
path: .gem_rbs_collection
|
|
1121
1137
|
|
|
1122
1138
|
# gems:
|
|
1139
|
+
# # RBS for a library that doesn't appear in Gemfile.lock, such as a non-gem standard library.
|
|
1140
|
+
# - name: socket
|
|
1141
|
+
#
|
|
1123
1142
|
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
|
1124
1143
|
# - name: GEM_NAME
|
|
1125
1144
|
# ignore: true
|
|
1126
1145
|
YAML
|
|
1127
|
-
stdout.puts
|
|
1146
|
+
stdout.puts <<~MESSAGE
|
|
1147
|
+
created: #{config_path}
|
|
1148
|
+
|
|
1149
|
+
rbs collection installs RBS files for the gems in your Gemfile.lock.
|
|
1150
|
+
Gems in Gemfile.lock don't need to be listed anywhere.
|
|
1151
|
+
|
|
1152
|
+
Next steps:
|
|
1153
|
+
$ echo "/.gem_rbs_collection/" >> .gitignore
|
|
1154
|
+
$ rbs collection install # writes rbs_collection.lock.yaml; keep it in version control
|
|
1155
|
+
MESSAGE
|
|
1128
1156
|
when 'clean'
|
|
1129
1157
|
unless lock_path.exist?
|
|
1130
|
-
puts "#{lock_path} should exist to clean"
|
|
1158
|
+
stderr.puts "#{lock_path} should exist to clean"
|
|
1131
1159
|
return 1
|
|
1132
1160
|
end
|
|
1133
1161
|
Collection::Cleaner.new(lockfile_path: lock_path)
|
|
1134
1162
|
when 'help', 'hel', 'he', 'h'
|
|
1135
|
-
puts opts.help
|
|
1163
|
+
stdout.puts opts.help
|
|
1136
1164
|
else
|
|
1137
|
-
puts opts.help
|
|
1165
|
+
stdout.puts opts.help
|
|
1138
1166
|
return 1
|
|
1139
1167
|
end
|
|
1140
1168
|
|
|
1141
1169
|
0
|
|
1142
1170
|
end
|
|
1143
1171
|
|
|
1172
|
+
def collection_config_available?(config_path)
|
|
1173
|
+
return true if config_path.exist?
|
|
1174
|
+
|
|
1175
|
+
stderr.puts "#{config_path} not found. Run `rbs collection init` to generate it."
|
|
1176
|
+
false
|
|
1177
|
+
end
|
|
1178
|
+
|
|
1179
|
+
def bundler_definition
|
|
1180
|
+
definition = Bundler.definition
|
|
1181
|
+
return definition if definition.lockfile.file?
|
|
1182
|
+
|
|
1183
|
+
stderr.puts "#{definition.lockfile} not found. Run `bundle install` to generate it."
|
|
1184
|
+
nil
|
|
1185
|
+
rescue Bundler::GemfileNotFound
|
|
1186
|
+
stderr.puts "Gemfile not found. `rbs collection` reads the gems to install from Gemfile.lock."
|
|
1187
|
+
nil
|
|
1188
|
+
end
|
|
1189
|
+
|
|
1144
1190
|
def collection_options(args)
|
|
1145
1191
|
OptionParser.new do |opts|
|
|
1146
1192
|
opts.banner = <<~HELP
|
|
@@ -99,8 +99,6 @@ module RBS
|
|
|
99
99
|
|
|
100
100
|
private
|
|
101
101
|
|
|
102
|
-
CAN_CALL_KEYWORD_INIT_P = Struct.new(:tmp).respond_to?(:keyword_init?)
|
|
103
|
-
|
|
104
102
|
def build_super_class
|
|
105
103
|
AST::Declarations::Class::Super.new(name: TypeName.parse("::Struct"), args: [untyped], location: nil)
|
|
106
104
|
end
|
|
@@ -118,21 +116,16 @@ module RBS
|
|
|
118
116
|
[:new, :[]].map do |name|
|
|
119
117
|
new_overloads = [] #: Array[AST::Members::MethodDefinition::Overload]
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
when nil
|
|
128
|
-
new_overloads << build_overload_for_positional_arguments
|
|
129
|
-
new_overloads << build_overload_for_keyword_arguments
|
|
130
|
-
else
|
|
131
|
-
raise
|
|
132
|
-
end
|
|
133
|
-
else
|
|
119
|
+
case @target_class.keyword_init?
|
|
120
|
+
when false
|
|
121
|
+
new_overloads << build_overload_for_positional_arguments
|
|
122
|
+
when true
|
|
123
|
+
new_overloads << build_overload_for_keyword_arguments
|
|
124
|
+
when nil
|
|
134
125
|
new_overloads << build_overload_for_positional_arguments
|
|
135
126
|
new_overloads << build_overload_for_keyword_arguments
|
|
127
|
+
else
|
|
128
|
+
raise
|
|
136
129
|
end
|
|
137
130
|
|
|
138
131
|
AST::Members::MethodDefinition.new(
|
|
@@ -178,8 +171,6 @@ module RBS
|
|
|
178
171
|
|
|
179
172
|
# def self.keyword_init?: () -> bool?
|
|
180
173
|
def build_s_keyword_init_p
|
|
181
|
-
return [] unless CAN_CALL_KEYWORD_INIT_P
|
|
182
|
-
|
|
183
174
|
return_type = @target_class.keyword_init?.nil? \
|
|
184
175
|
? Types::Bases::Nil.new(location: nil)
|
|
185
176
|
: Types::Literal.new(literal: @target_class.keyword_init?, location: nil)
|
data/lib/rbs/version.rb
CHANGED
data/sig/cli.rbs
CHANGED
|
@@ -76,6 +76,12 @@ module RBS
|
|
|
76
76
|
|
|
77
77
|
def run_collection: (Array[String], LibraryOptions) -> Integer
|
|
78
78
|
|
|
79
|
+
# Returns `true` if the collection config exists, otherwise prints a message to `stderr` and returns `false`
|
|
80
|
+
def collection_config_available?: (Pathname) -> bool
|
|
81
|
+
|
|
82
|
+
# Returns `nil` if `Gemfile` or `Gemfile.lock` is not found, after printing a message to `stderr`
|
|
83
|
+
def bundler_definition: () -> Bundler::Definition?
|
|
84
|
+
|
|
79
85
|
def run_annotate: (Array[String], top) -> Integer
|
|
80
86
|
|
|
81
87
|
def run_subtract: (Array[String], top) -> Integer
|
data/sig/prototype/runtime.rbs
CHANGED
data/sig/shims/bundler.rbs
CHANGED