Skip to content

Commit 70e340d

Browse files
authored
Merge pull request #2225 from euglena1215/net-http-start
stdlib: Accept keyword arguments in `Net::HTTP.start`
2 parents f62e8a3 + 1ce65bd commit 70e340d

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

stdlib/net-http/0/net-http.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,8 @@ module Net
978978
# Note: If `port` is `nil` and `opts[:use_ssl]` is a truthy value, the value
979979
# passed to `new` is Net::HTTP.https_default_port, not `port`.
980980
#
981-
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]? opt) -> Net::HTTP
982-
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]? opt) { (Net::HTTP) -> T } -> T
981+
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]?, **untyped opt) -> Net::HTTP
982+
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]?, **untyped opt) { (Net::HTTP) -> T } -> T
983983

984984
# <!--
985985
# rdoc-file=lib/net/http.rb

test/stdlib/Net_HTTP_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ def test_new
5151
assert_send_type "(String, Integer, nil, nil, nil, nil, nil) -> Net::HTTP",
5252
Net::HTTP, :new, 'www.ruby-lang.org', 80, nil, nil, nil, nil, nil
5353
end
54+
55+
def test_start
56+
assert_send_type "(String, Integer) -> Net::HTTP",
57+
Net::HTTP, :start, 'www.ruby-lang.org', 80
58+
assert_send_type "(String, Integer, use_ssl: bool) -> Net::HTTP",
59+
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true
60+
assert_send_type "(String, Integer) { (Net::HTTP) -> untyped } -> untyped",
61+
Net::HTTP, :start, 'www.ruby-lang.org', 80 do |net_http| net_http.class end
62+
assert_send_type "(String, Integer, use_ssl: bool) { (Net::HTTP) -> untyped } -> untyped",
63+
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true do |net_http| net_http.class end
64+
65+
assert_send_type(
66+
"(String, Integer, nil, nil, nil, nil, Hash[Symbol, untyped]) { (Net::HTTP) -> Class } -> Class",
67+
Net::HTTP, :start, 'www.ruby-lang.org', 443, nil, nil, nil, nil, { use_ssl: true }, &->(net_http) { net_http.class }
68+
)
69+
end
5470
end
5571

5672
class NetInstanceTest < Test::Unit::TestCase

test/typecheck/net_http/Steepfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
D = Steep::Diagnostic
2+
3+
target :test do
4+
signature "."
5+
check "."
6+
library "net-http"
7+
configure_code_diagnostics(D::Ruby.all_error)
8+
end

test/typecheck/net_http/start.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Passing keyword args is allowed.
2+
Net::HTTP.start('example.com', open_timeout: 10)
3+
4+
# Passing a hash object is also allowed, but it needs the predecessor arguments.
5+
Net::HTTP.start('example.com', 443, nil, nil, nil, nil, { open_timeout: 10, read_timeout: 10 })

0 commit comments

Comments
 (0)