Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib: Accept keyword arguments in Net::HTTP.start #2225

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/net-http/0/net-http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ module Net
# Note: If `port` is `nil` and `opts[:use_ssl]` is a truthy value, the value
# passed to `new` is Net::HTTP.https_default_port, not `port`.
#
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
| [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
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
| [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

# <!--
# rdoc-file=lib/net/http.rb
Expand Down
16 changes: 16 additions & 0 deletions test/stdlib/Net_HTTP_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ def test_new
assert_send_type "(String, Integer, nil, nil, nil, nil, nil) -> Net::HTTP",
Net::HTTP, :new, 'www.ruby-lang.org', 80, nil, nil, nil, nil, nil
end

def test_start
assert_send_type "(String, Integer) -> Net::HTTP",
Net::HTTP, :start, 'www.ruby-lang.org', 80
assert_send_type "(String, Integer, use_ssl: bool) -> Net::HTTP",
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true
assert_send_type "(String, Integer) { (Net::HTTP) -> untyped } -> untyped",
Net::HTTP, :start, 'www.ruby-lang.org', 80 do |net_http| net_http.class end
assert_send_type "(String, Integer, use_ssl: bool) { (Net::HTTP) -> untyped } -> untyped",
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true do |net_http| net_http.class end

assert_send_type(
"(String, Integer, nil, nil, nil, nil, Hash[Symbol, untyped]) { (Net::HTTP) -> Class } -> Class",
Net::HTTP, :start, 'www.ruby-lang.org', 443, nil, nil, nil, nil, { use_ssl: true }, &->(net_http) { net_http.class }
)
end
end

class NetInstanceTest < Test::Unit::TestCase
Expand Down
8 changes: 8 additions & 0 deletions test/typecheck/net_http/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
D = Steep::Diagnostic

target :test do
signature "."
check "."
library "net-http"
configure_code_diagnostics(D::Ruby.all_error)
end
5 changes: 5 additions & 0 deletions test/typecheck/net_http/start.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Passing keyword args is allowed.
Net::HTTP.start('example.com', open_timeout: 10)

# Passing a hash object is also allowed, but it needs the predecessor arguments.
Net::HTTP.start('example.com', 443, nil, nil, nil, nil, { open_timeout: 10, read_timeout: 10 })
Loading