rbs 1.2.0 → 1.3.2

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -1
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +53 -0
  5. data/README.md +1 -1
  6. data/Rakefile +9 -0
  7. data/Steepfile +1 -0
  8. data/core/array.rbs +1 -1
  9. data/core/basic_object.rbs +1 -1
  10. data/core/io.rbs +1 -1
  11. data/core/kernel.rbs +2 -2
  12. data/core/marshal.rbs +4 -3
  13. data/docs/rbs_by_example.md +328 -0
  14. data/docs/sigs.md +3 -1
  15. data/docs/stdlib.md +1 -1
  16. data/docs/syntax.md +0 -3
  17. data/lib/rbs/definition_builder.rb +2 -18
  18. data/lib/rbs/definition_builder/ancestor_builder.rb +9 -2
  19. data/lib/rbs/errors.rb +36 -0
  20. data/lib/rbs/parser.rb +913 -892
  21. data/lib/rbs/parser.y +10 -6
  22. data/lib/rbs/prototype/rb.rb +7 -3
  23. data/lib/rbs/prototype/runtime.rb +118 -42
  24. data/lib/rbs/version.rb +1 -1
  25. data/rbs.gemspec +1 -1
  26. data/sig/ancestor_builder.rbs +2 -0
  27. data/sig/errors.rbs +15 -0
  28. data/sig/namespace.rbs +1 -1
  29. data/sig/polyfill.rbs +0 -18
  30. data/stdlib/dbm/0/dbm.rbs +43 -30
  31. data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
  32. data/stdlib/net-http/0/net-http.rbs +1846 -0
  33. data/stdlib/optparse/0/optparse.rbs +1214 -0
  34. data/stdlib/resolv/0/resolv.rbs +1504 -0
  35. data/stdlib/socket/0/addrinfo.rbs +469 -0
  36. data/stdlib/socket/0/basic_socket.rbs +503 -0
  37. data/stdlib/socket/0/ip_socket.rbs +72 -0
  38. data/stdlib/socket/0/socket.rbs +2687 -0
  39. data/stdlib/socket/0/tcp_server.rbs +177 -0
  40. data/stdlib/socket/0/tcp_socket.rbs +35 -0
  41. data/stdlib/socket/0/udp_socket.rbs +111 -0
  42. data/stdlib/socket/0/unix_server.rbs +154 -0
  43. data/stdlib/socket/0/unix_socket.rbs +132 -0
  44. data/stdlib/timeout/0/timeout.rbs +5 -0
  45. data/steep/Gemfile.lock +12 -12
  46. metadata +16 -12
  47. data/bin/annotate-with-rdoc +0 -153
  48. data/bin/console +0 -14
  49. data/bin/query-rdoc +0 -103
  50. data/bin/rbs-prof +0 -9
  51. data/bin/run_in_md.rb +0 -49
  52. data/bin/setup +0 -8
  53. data/bin/sort +0 -89
  54. data/bin/steep +0 -4
  55. data/bin/test_runner.rb +0 -29
@@ -0,0 +1,132 @@
1
+ # UNIXSocket represents a UNIX domain stream client socket.
2
+ class UNIXSocket < BasicSocket
3
+ # Creates a pair of sockets connected to each other.
4
+ #
5
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
6
+ #
7
+ # *protocol* should be a protocol defined in the domain. 0 is default protocol
8
+ # for the domain.
9
+ #
10
+ # s1, s2 = UNIXSocket.pair
11
+ # s1.send "a", 0
12
+ # s1.send "b", 0
13
+ # p s2.recv(10) #=> "ab"
14
+ #
15
+ def self.pair: (?Symbol socktype, ?Integer protocol) -> [instance, instance]
16
+
17
+ # Creates a pair of sockets connected to each other.
18
+ #
19
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
20
+ #
21
+ # *protocol* should be a protocol defined in the domain. 0 is default protocol
22
+ # for the domain.
23
+ #
24
+ # s1, s2 = UNIXSocket.pair
25
+ # s1.send "a", 0
26
+ # s1.send "b", 0
27
+ # p s2.recv(10) #=> "ab"
28
+ #
29
+ def self.socketpair: (?Symbol socktype, ?Integer protocol) -> [instance, instance]
30
+
31
+ public
32
+
33
+ # Returns the local address as an array which contains address_family and
34
+ # unix_path.
35
+ #
36
+ # Example
37
+ # serv = UNIXServer.new("/tmp/sock")
38
+ # p serv.addr #=> ["AF_UNIX", "/tmp/sock"]
39
+ #
40
+ def addr: () -> [String, String]
41
+
42
+ # Returns the path of the local address of unixsocket.
43
+ #
44
+ # s = UNIXServer.new("/tmp/sock")
45
+ # p s.path #=> "/tmp/sock"
46
+ #
47
+ def path: () -> String
48
+
49
+ # Returns the remote address as an array which contains address_family and
50
+ # unix_path.
51
+ #
52
+ # Example
53
+ # serv = UNIXServer.new("/tmp/sock")
54
+ # c = UNIXSocket.new("/tmp/sock")
55
+ # p c.peeraddr #=> ["AF_UNIX", "/tmp/sock"]
56
+ #
57
+ def peeraddr: () -> [String, String]
58
+
59
+ # Example
60
+ #
61
+ # UNIXServer.open("/tmp/sock") {|serv|
62
+ # UNIXSocket.open("/tmp/sock") {|c|
63
+ # s = serv.accept
64
+ #
65
+ # c.send_io STDOUT
66
+ # stdout = s.recv_io
67
+ #
68
+ # p STDOUT.fileno #=> 1
69
+ # p stdout.fileno #=> 7
70
+ #
71
+ # stdout.puts "hello" # outputs "hello\n" to standard output.
72
+ # }
73
+ # }
74
+ #
75
+ # *klass* will determine the class of *io* returned (using the IO.for_fd
76
+ # singleton method or similar). If *klass* is `nil`, an integer file descriptor
77
+ # is returned.
78
+ #
79
+ # *mode* is the same as the argument passed to IO.for_fd
80
+ #
81
+ def recv_io: (?singleton(BasicSocket), ?String mode) -> BasicSocket
82
+
83
+ # Receives a message via *unixsocket*.
84
+ #
85
+ # *maxlen* is the maximum number of bytes to receive.
86
+ #
87
+ # *flags* should be a bitwise OR of Socket::MSG_* constants.
88
+ #
89
+ # *outbuf* will contain only the received data after the method call even if it
90
+ # is not empty at the beginning.
91
+ #
92
+ # s1 = Socket.new(:UNIX, :DGRAM, 0)
93
+ # s1_ai = Addrinfo.unix("/tmp/sock1")
94
+ # s1.bind(s1_ai)
95
+ #
96
+ # s2 = Socket.new(:UNIX, :DGRAM, 0)
97
+ # s2_ai = Addrinfo.unix("/tmp/sock2")
98
+ # s2.bind(s2_ai)
99
+ # s3 = UNIXSocket.for_fd(s2.fileno)
100
+ #
101
+ # s1.send "a", 0, s2_ai
102
+ # p s3.recvfrom(10) #=> ["a", ["AF_UNIX", "/tmp/sock1"]]
103
+ #
104
+ def recvfrom: (Integer maxlen, ?Integer flags, ?String outbuf) -> [String, [String, String]]
105
+
106
+ # Sends *io* as file descriptor passing.
107
+ #
108
+ # s1, s2 = UNIXSocket.pair
109
+ #
110
+ # s1.send_io STDOUT
111
+ # stdout = s2.recv_io
112
+ #
113
+ # p STDOUT.fileno #=> 1
114
+ # p stdout.fileno #=> 6
115
+ #
116
+ # stdout.puts "hello" # outputs "hello\n" to standard output.
117
+ #
118
+ # *io* may be any kind of IO object or integer file descriptor.
119
+ #
120
+ def send_io: (BasicSocket | Integer) -> void
121
+
122
+ private
123
+
124
+ # Creates a new UNIX client socket connected to *path*.
125
+ #
126
+ # require 'socket'
127
+ #
128
+ # s = UNIXSocket.new("/tmp/sock")
129
+ # s.send "hello", 0
130
+ #
131
+ def initialize: (String path) -> untyped
132
+ end
@@ -54,4 +54,9 @@ module Timeout
54
54
  def self?.timeout: [T] (Numeric? sec, ?singleton(Exception) klass, ?String message) { (Numeric sec) -> T } -> T
55
55
  end
56
56
 
57
+ # Raised by Timeout.timeout when the block times out.
58
+ class Timeout::Error < RuntimeError
59
+ attr_reader thread: Thread?
60
+ end
61
+
57
62
  Timeout::VERSION: String
data/steep/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (6.1.3.1)
4
+ activesupport (6.1.3.2)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 1.6, < 2)
7
7
  minitest (>= 5.1)
@@ -9,36 +9,36 @@ GEM
9
9
  zeitwerk (~> 2.3)
10
10
  ast (2.4.2)
11
11
  concurrent-ruby (1.1.8)
12
- ffi (1.15.0)
12
+ ffi (1.15.1)
13
13
  i18n (1.8.10)
14
14
  concurrent-ruby (~> 1.0)
15
- language_server-protocol (3.16.0.0)
15
+ language_server-protocol (3.16.0.1)
16
16
  listen (3.5.1)
17
17
  rb-fsevent (~> 0.10, >= 0.10.3)
18
18
  rb-inotify (~> 0.9, >= 0.9.10)
19
19
  minitest (5.14.4)
20
20
  parallel (1.20.1)
21
- parser (3.0.0.0)
21
+ parser (3.0.1.1)
22
22
  ast (~> 2.4.1)
23
23
  rainbow (3.0.0)
24
- rb-fsevent (0.10.4)
24
+ rb-fsevent (0.11.0)
25
25
  rb-inotify (0.10.1)
26
26
  ffi (~> 1.0)
27
- rbs (1.1.1)
28
- steep (0.43.1)
27
+ rbs (1.2.0)
28
+ steep (0.44.1)
29
29
  activesupport (>= 5.1)
30
30
  language_server-protocol (>= 3.15, < 4.0)
31
31
  listen (~> 3.0)
32
32
  parallel (>= 1.0.0)
33
33
  parser (>= 2.7)
34
34
  rainbow (>= 2.2.2, < 4.0)
35
- rbs (~> 1.1.0)
35
+ rbs (>= 1.2.0)
36
36
  terminal-table (>= 2, < 4)
37
- terminal-table (3.0.0)
38
- unicode-display_width (~> 1.1, >= 1.1.1)
37
+ terminal-table (3.0.1)
38
+ unicode-display_width (>= 1.1.1, < 3)
39
39
  tzinfo (2.0.4)
40
40
  concurrent-ruby (~> 1.0)
41
- unicode-display_width (1.7.0)
41
+ unicode-display_width (2.0.0)
42
42
  zeitwerk (2.4.2)
43
43
 
44
44
  PLATFORMS
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  steep
49
49
 
50
50
  BUNDLED WITH
51
- 2.2.3
51
+ 2.2.15
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-21 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -29,15 +29,6 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - Steepfile
32
- - bin/annotate-with-rdoc
33
- - bin/console
34
- - bin/query-rdoc
35
- - bin/rbs-prof
36
- - bin/run_in_md.rb
37
- - bin/setup
38
- - bin/sort
39
- - bin/steep
40
- - bin/test_runner.rb
41
32
  - core/array.rbs
42
33
  - core/basic_object.rbs
43
34
  - core/binding.rbs
@@ -95,6 +86,7 @@ files:
95
86
  - core/unbound_method.rbs
96
87
  - core/warning.rbs
97
88
  - docs/CONTRIBUTING.md
89
+ - docs/rbs_by_example.md
98
90
  - docs/repo.md
99
91
  - docs/sigs.md
100
92
  - docs/stdlib.md
@@ -222,12 +214,15 @@ files:
222
214
  - stdlib/logger/0/severity.rbs
223
215
  - stdlib/monitor/0/monitor.rbs
224
216
  - stdlib/mutex_m/0/mutex_m.rbs
217
+ - stdlib/net-http/0/net-http.rbs
218
+ - stdlib/optparse/0/optparse.rbs
225
219
  - stdlib/pathname/0/pathname.rbs
226
220
  - stdlib/prettyprint/0/prettyprint.rbs
227
221
  - stdlib/prime/0/integer-extension.rbs
228
222
  - stdlib/prime/0/prime.rbs
229
223
  - stdlib/pstore/0/pstore.rbs
230
224
  - stdlib/pty/0/pty.rbs
225
+ - stdlib/resolv/0/resolv.rbs
231
226
  - stdlib/rubygems/0/basic_specification.rbs
232
227
  - stdlib/rubygems/0/config_file.rbs
233
228
  - stdlib/rubygems/0/dependency_installer.rbs
@@ -246,6 +241,15 @@ files:
246
241
  - stdlib/set/0/set.rbs
247
242
  - stdlib/shellwords/0/shellwords.rbs
248
243
  - stdlib/singleton/0/singleton.rbs
244
+ - stdlib/socket/0/addrinfo.rbs
245
+ - stdlib/socket/0/basic_socket.rbs
246
+ - stdlib/socket/0/ip_socket.rbs
247
+ - stdlib/socket/0/socket.rbs
248
+ - stdlib/socket/0/tcp_server.rbs
249
+ - stdlib/socket/0/tcp_socket.rbs
250
+ - stdlib/socket/0/udp_socket.rbs
251
+ - stdlib/socket/0/unix_server.rbs
252
+ - stdlib/socket/0/unix_socket.rbs
249
253
  - stdlib/strscan/0/string_scanner.rbs
250
254
  - stdlib/time/0/time.rbs
251
255
  - stdlib/timeout/0/timeout.rbs
@@ -290,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
294
  - !ruby/object:Gem::Version
291
295
  version: '0'
292
296
  requirements: []
293
- rubygems_version: 3.2.3
297
+ rubygems_version: 3.2.15
294
298
  signing_key:
295
299
  specification_version: 4
296
300
  summary: Type signature for Ruby.
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
- require "rdoc"
6
-
7
- def store_for_class(name, stores:)
8
- stores.find do |store|
9
- store.find_class_named(name) || store.find_module_named(name)
10
- end
11
- end
12
-
13
- def format_comment(comment)
14
- out = RDoc::Markup::Document.new
15
- out << comment
16
- formatter = RDoc::Markup::ToMarkdown.new
17
- out.accept(formatter).lines.map(&:rstrip).join("\n")
18
- end
19
-
20
- def comment_for_constant(decl, stores:)
21
- class_name = decl.name.namespace.to_type_name.to_s
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- if klass
27
- constant = klass.constants.find do |const|
28
- const.name == decl.name.name.to_s
29
- end
30
-
31
- if constant&.documented?
32
- string = format_comment(constant.comment)
33
- RBS::AST::Comment.new(location: nil, string: string)
34
- end
35
- end
36
- end
37
-
38
- def comment_for_class(decl, stores:)
39
- name = decl.name.to_s
40
- klass = store_for_class(name, stores: stores)&.yield_self {|store|
41
- store.find_class_named(name) || store.find_module_named(name)
42
- }
43
-
44
- if klass&.documented?
45
- string = format_comment(klass.comment)
46
- RBS::AST::Comment.new(location: nil, string: string)
47
- end
48
- end
49
-
50
- def comment_for_method(klass, method, stores:)
51
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
52
-
53
- if method&.documented?
54
- out = RDoc::Markup::Document.new
55
-
56
- out << method.comment
57
-
58
- if method.arglists
59
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
60
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
61
- out << RDoc::Markup::Verbatim.new(*arglists)
62
- end
63
-
64
- string = out.accept(RDoc::Markup::ToMarkdown.new)
65
- RBS::AST::Comment.new(location: nil, string: string)
66
- end
67
-
68
- rescue RDoc::Store::MissingFileError
69
- puts " 👺 No document found for #{klass}#{method}"
70
- nil
71
- end
72
-
73
- if ARGV.empty?
74
- puts 'annotate-with-rdoc [RBS files...]'
75
- exit
76
- end
77
-
78
- def print_members(stores, klass_name, members)
79
- members.each do |member|
80
- case member
81
- when RBS::AST::Members::MethodDefinition
82
- puts " Processing #{member.name}..."
83
-
84
- method_name = case
85
- when member.instance?
86
- "##{member.name}"
87
- when member.singleton?
88
- "::#{member.name}"
89
- end
90
-
91
- comment = comment_for_method(klass_name, method_name, stores: stores)
92
-
93
- unless comment
94
- if member.instance? && member.name == :initialize
95
- comment = comment_for_method(klass_name, '::new', stores: stores)
96
- end
97
- end
98
-
99
- member.instance_variable_set(:@comment, comment)
100
- when RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor, RBS::AST::Members::AttrWriter
101
- puts " 👻 Attributes not supported (#{klass_name})"
102
- when RBS::AST::Members::Alias
103
- puts " Processing #{member.new_name}(alias)..."
104
- prefix = case
105
- when member.instance?
106
- "#"
107
- when member.singleton?
108
- "."
109
- end
110
- name = "#{prefix}#{member.new_name}"
111
-
112
- comment = comment_for_method(klass_name, name, stores: stores)
113
- member.instance_variable_set(:@comment, comment)
114
- end
115
- end
116
- end
117
-
118
- stores = []
119
- RDoc::RI::Paths.each true, true, false, false do |path, type|
120
- puts "Loading store from #{path}..."
121
- store = RDoc::RI::Store.new(path, type)
122
- store.load_all
123
- stores << store
124
- end
125
-
126
- ARGV.map {|f| Pathname(f) }.each do |path|
127
- puts "Opening #{path}..."
128
-
129
- buffer = RBS::Buffer.new(name: path, content: path.read)
130
- sigs = RBS::Parser.parse_signature(buffer)
131
-
132
- sigs.each do |decl|
133
- case decl
134
- when RBS::AST::Declarations::Constant
135
- puts " Importing documentation for #{decl.name}..."
136
- comment = comment_for_constant(decl, stores: stores)
137
- decl.instance_variable_set(:@comment, comment)
138
- when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
139
- puts " Importing documentation for #{decl.name}..."
140
- comment = comment_for_class(decl, stores: stores)
141
- decl.instance_variable_set(:@comment, comment)
142
-
143
- print_members stores, decl.name.to_s, decl.members
144
- end
145
- end
146
-
147
- puts "Writing #{path}..."
148
- path.open('w') do |out|
149
- writer = RBS::Writer.new(out: out)
150
- writer.write sigs
151
- end
152
- end
153
-
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)