Skip to content

Commit c430720

Browse files
authored
Merge pull request #20704 from Homebrew/revert-20644-dug/deep-typecheck-specs
Revert "Enable recursive typechecking in specs"
2 parents 3a94358 + a39d427 commit c430720

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+141
-224
lines changed

Library/Homebrew/bottle_specification.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class BottleSpecification
99

1010
attr_reader :collector
1111

12-
sig { returns(T::Hash[Symbol, T.untyped]) }
12+
sig { returns(T::Hash[String, T.untyped]) }
1313
attr_reader :root_url_specs
1414

1515
sig { returns(String) }
@@ -20,7 +20,7 @@ def initialize
2020
@rebuild = T.let(0, Integer)
2121
@repository = T.let(Homebrew::DEFAULT_REPOSITORY, String)
2222
@collector = T.let(Utils::Bottles::Collector.new, Utils::Bottles::Collector)
23-
@root_url_specs = T.let({}, T::Hash[Symbol, T.untyped])
23+
@root_url_specs = T.let({}, T::Hash[String, T.untyped])
2424
@root_url = T.let(nil, T.nilable(String))
2525
end
2626

Library/Homebrew/build.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ def install
135135
end
136136

137137
new_env = {
138-
"TMPDIR" => HOMEBREW_TEMP.to_s,
139-
"TEMP" => HOMEBREW_TEMP.to_s,
140-
"TMP" => HOMEBREW_TEMP.to_s,
138+
"TMPDIR" => HOMEBREW_TEMP,
139+
"TEMP" => HOMEBREW_TEMP,
140+
"TMP" => HOMEBREW_TEMP,
141141
}
142142

143143
with_env(new_env) do

Library/Homebrew/bundle/skipper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def tap_failed!(tap_name)
3737

3838
private
3939

40-
sig { returns(T::Hash[Symbol, T.nilable(T::Array[String])]) }
40+
sig { returns(T::Hash[Symbol, T::Array[String]]) }
4141
def skipped_entries
4242
return @skipped_entries if @skipped_entries
4343

44-
@skipped_entries ||= T.let({}, T.nilable(T::Hash[Symbol, T.nilable(T::Array[String])]))
44+
@skipped_entries ||= T.let({}, T.nilable(T::Hash[Symbol, T::Array[String]]))
4545
[:brew, :cask, :mas, :tap, :whalebrew].each do |type|
4646
@skipped_entries[type] =
4747
ENV["HOMEBREW_BUNDLE_#{type.to_s.upcase}_SKIP"]&.split

Library/Homebrew/cask/config.rb

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module Cask
1212
#
1313
# @api internal
1414
class Config
15-
ConfigHash = T.type_alias { T::Hash[Symbol, T.any(LazyObject, String, Pathname, T::Array[String])] }
1615
DEFAULT_DIRS = T.let(
1716
{
1817
appdir: "/Applications",
@@ -34,8 +33,7 @@ class Config
3433
T::Hash[Symbol, String],
3534
)
3635

37-
# runtime recursive evaluation forces the LazyObject to be evaluated
38-
T::Sig::WithoutRuntime.sig { returns(T::Hash[Symbol, T.any(LazyObject, String)]) }
36+
sig { returns(T::Hash[Symbol, String]) }
3937
def self.defaults
4038
{
4139
languages: LazyObject.new { ::OS::Mac.languages },
@@ -69,59 +67,69 @@ def self.from_args(args)
6967

7068
sig { params(json: String, ignore_invalid_keys: T::Boolean).returns(T.attached_class) }
7169
def self.from_json(json, ignore_invalid_keys: false)
72-
config = JSON.parse(json, symbolize_names: true)
70+
config = JSON.parse(json)
7371

7472
new(
75-
default: config.fetch(:default, {}),
76-
env: config.fetch(:env, {}),
77-
explicit: config.fetch(:explicit, {}),
73+
default: config.fetch("default", {}),
74+
env: config.fetch("env", {}),
75+
explicit: config.fetch("explicit", {}),
7876
ignore_invalid_keys:,
7977
)
8078
end
8179

82-
sig { params(config: ConfigHash).returns(ConfigHash) }
80+
sig {
81+
params(
82+
config: T::Enumerable[
83+
[T.any(String, Symbol), T.any(String, Pathname, T::Array[String])],
84+
],
85+
).returns(
86+
T::Hash[Symbol, T.any(String, Pathname, T::Array[String])],
87+
)
88+
}
8389
def self.canonicalize(config)
8490
config.to_h do |k, v|
85-
if DEFAULT_DIRS.key?(k)
91+
key = k.to_sym
92+
93+
if DEFAULT_DIRS.key?(key)
8694
raise TypeError, "Invalid path for default dir #{k}: #{v.inspect}" if v.is_a?(Array)
8795

88-
[k, Pathname(v.to_s).expand_path]
96+
[key, Pathname(v).expand_path]
8997
else
90-
[k, v]
98+
[key, v]
9199
end
92100
end
93101
end
94102

95103
# Get the explicit configuration.
96104
#
97105
# @api internal
98-
sig { returns(ConfigHash) }
106+
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
99107
attr_accessor :explicit
100108

101109
sig {
102110
params(
103-
default: T.nilable(ConfigHash),
104-
env: T.nilable(ConfigHash),
105-
explicit: ConfigHash,
111+
default: T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]),
112+
env: T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]),
113+
explicit: T::Hash[Symbol, T.any(String, Pathname, T::Array[String])],
106114
ignore_invalid_keys: T::Boolean,
107115
).void
108116
}
109117
def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false)
110118
if default
111119
@default = T.let(
112120
self.class.canonicalize(self.class.defaults.merge(default)),
113-
T.nilable(ConfigHash),
121+
T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]),
114122
)
115123
end
116124
if env
117125
@env = T.let(
118126
self.class.canonicalize(env),
119-
T.nilable(ConfigHash),
127+
T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]),
120128
)
121129
end
122130
@explicit = T.let(
123131
self.class.canonicalize(explicit),
124-
ConfigHash,
132+
T::Hash[Symbol, T.any(String, Pathname, T::Array[String])],
125133
)
126134

127135
if ignore_invalid_keys
@@ -134,26 +142,26 @@ def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false)
134142
@explicit.assert_valid_keys(*self.class.defaults.keys)
135143
end
136144

137-
sig { returns(ConfigHash) }
145+
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
138146
def default
139147
@default ||= self.class.canonicalize(self.class.defaults)
140148
end
141149

142-
sig { returns(ConfigHash) }
150+
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
143151
def env
144152
@env ||= self.class.canonicalize(
145153
Homebrew::EnvConfig.cask_opts
146154
.select { |arg| arg.include?("=") }
147155
.map { |arg| T.cast(arg.split("=", 2), [String, String]) }
148-
.to_h do |(flag, value)|
156+
.map do |(flag, value)|
149157
key = flag.sub(/^--/, "")
150158
# converts --language flag to :languages config key
151159
if key == "language"
152160
key = "languages"
153161
value = value.split(",")
154162
end
155163

156-
[key.to_sym, value]
164+
[key, value]
157165
end,
158166
)
159167
end

Library/Homebrew/cask/tab.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Tab < ::AbstractTab
1111
sig { returns(T.nilable(T::Array[T.untyped])) }
1212
attr_accessor :uninstall_artifacts
1313

14-
sig { params(attributes: T.any(T::Hash[String, T.untyped], T::Hash[Symbol, T.untyped])).void }
14+
sig { params(attributes: T::Hash[String, T.untyped]).void }
1515
def initialize(attributes = {})
1616
@uninstall_flight_blocks = T.let(nil, T.nilable(T::Boolean))
1717
@uninstall_artifacts = T.let(nil, T.nilable(T::Array[T.untyped]))

Library/Homebrew/cask/url.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class URL
5454
revisions: T.nilable(T::Hash[T.any(Symbol, String), String]),
5555
revision: T.nilable(String),
5656
trust_cert: T.nilable(T::Boolean),
57-
cookies: T.nilable(T::Hash[T.any(String, Symbol), String]),
57+
cookies: T.nilable(T::Hash[String, String]),
5858
referer: T.nilable(T.any(URI::Generic, String)),
5959
header: T.nilable(T.any(String, T::Array[String])),
6060
user_agent: T.nilable(T.any(Symbol, String)),
@@ -80,8 +80,7 @@ def initialize(
8080
specs[:revisions] = @revisions = T.let(revisions, T.nilable(T::Hash[T.any(Symbol, String), String]))
8181
specs[:revision] = @revision = T.let(revision, T.nilable(String))
8282
specs[:trust_cert] = @trust_cert = T.let(trust_cert, T.nilable(T::Boolean))
83-
specs[:cookies] =
84-
@cookies = T.let(cookies&.transform_keys(&:to_s), T.nilable(T::Hash[String, String]))
83+
specs[:cookies] = @cookies = T.let(cookies, T.nilable(T::Hash[String, String]))
8584
specs[:referer] = @referer = T.let(referer, T.nilable(T.any(URI::Generic, String)))
8685
specs[:headers] = @header = T.let(header, T.nilable(T.any(String, T::Array[String])))
8786
specs[:user_agent] = @user_agent = T.let(user_agent || :default, T.nilable(T.any(Symbol, String)))

Library/Homebrew/cask_dependent.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def deps
4545
)
4646
end
4747

48-
sig { returns(T::Array[::Requirement]) }
48+
sig { returns(T::Array[CaskDependent::Requirement]) }
4949
def requirements
5050
@requirements ||= T.let(
5151
begin
@@ -73,7 +73,7 @@ def requirements
7373

7474
requirements
7575
end,
76-
T.nilable(T::Array[::Requirement]),
76+
T.nilable(T::Array[CaskDependent::Requirement]),
7777
)
7878
end
7979

Library/Homebrew/cli/args.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Args
99
# 1: long option name (e.g. "--debug")
1010
# 2: option description (e.g. "Print debugging information")
1111
# 3: whether the option is hidden
12-
OptionsType = T.type_alias { T::Array[[T.nilable(String), T.nilable(String), String, T::Boolean]] }
12+
OptionsType = T.type_alias { T::Array[[String, T.nilable(String), String, T::Boolean]] }
1313

1414
sig { returns(T::Array[String]) }
1515
attr_reader :options_only, :flags_only, :remaining
@@ -170,7 +170,7 @@ def option_to_name(option)
170170
sig { returns(T::Array[String]) }
171171
def cli_args
172172
@cli_args ||= @processed_options.filter_map do |short, long|
173-
option = T.must(long || short)
173+
option = long || short
174174
switch = :"#{option_to_name(option)}?"
175175
flag = option_to_name(option).to_sym
176176
if @table[switch] == true || @table[flag] == true

Library/Homebrew/cmd/outdated.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def print_outdated(formulae_or_casks)
127127
sig {
128128
params(
129129
formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)],
130-
).returns(T::Array[T::Hash[Symbol, T.untyped]])
130+
).returns(
131+
T::Array[T.any(T::Hash[String, T.untyped], T::Hash[String, T.untyped])],
132+
)
131133
}
132134
def json_info(formulae_or_casks)
133135
formulae_or_casks.map do |formula_or_cask|

Library/Homebrew/cmd/update-report.rb

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,6 @@ def install_from_api_message
430430
class Reporter
431431
include Utils::Output::Mixin
432432

433-
Report = T.type_alias do
434-
{
435-
A: T::Array[String],
436-
AC: T::Array[String],
437-
D: T::Array[String],
438-
DC: T::Array[String],
439-
M: T::Array[String],
440-
MC: T::Array[String],
441-
R: T::Array[[String, String]],
442-
RC: T::Array[[String, String]],
443-
}
444-
end
445-
446433
class ReporterRevisionUnsetError < RuntimeError
447434
sig { params(var_name: String).void }
448435
def initialize(var_name)
@@ -472,17 +459,14 @@ def initialize(tap, api_names_txt: nil, api_names_before_txt: nil, api_dir_prefi
472459
raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty?
473460
end
474461

475-
@report = T.let(nil, T.nilable(Report))
462+
@report = T.let(nil, T.nilable(T::Hash[Symbol, T::Array[String]]))
476463
end
477464

478-
sig { params(auto_update: T::Boolean).returns(Report) }
465+
sig { params(auto_update: T::Boolean).returns(T::Hash[Symbol, T::Array[String]]) }
479466
def report(auto_update: false)
480467
return @report if @report
481468

482-
@report = {
483-
A: [], AC: [], D: [], DC: [], M: [], MC: [], R: T.let([], T::Array[[String, String]]),
484-
RC: T.let([], T::Array[[String, String]])
485-
}
469+
@report = Hash.new { |h, k| h[k] = [] }
486470
return @report unless updated?
487471

488472
diff.each_line do |line|
@@ -810,15 +794,13 @@ class ReporterHub
810794

811795
sig { void }
812796
def initialize
813-
@hash = T.let({}, T::Hash[Symbol, T::Array[T.any(String, [String, String])]])
797+
@hash = T.let({}, T::Hash[Symbol, T::Array[String]])
814798
@reporters = T.let([], T::Array[Reporter])
815799
end
816800

817801
sig { params(key: Symbol).returns(T::Array[String]) }
818802
def select_formula_or_cask(key)
819-
raise "Unsupported key #{key}" unless [:A, :AC, :D, :DC, :M, :MC].include?(key)
820-
821-
T.cast(@hash.fetch(key, []), T::Array[String])
803+
@hash.fetch(key, [])
822804
end
823805

824806
sig { params(reporter: Reporter, auto_update: T::Boolean).void }

0 commit comments

Comments
 (0)