Skip to content

Commit 1a11875

Browse files
authored
Merge pull request #20705 from Homebrew/update-report-type-fix
cmd/update-report: fix type
2 parents c430720 + c952f1a commit 1a11875

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

+225
-142
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[String, T.untyped]) }
12+
sig { returns(T::Hash[Symbol, 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[String, T.untyped])
23+
@root_url_specs = T.let({}, T::Hash[Symbol, 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,
139-
"TEMP" => HOMEBREW_TEMP,
140-
"TMP" => HOMEBREW_TEMP,
138+
"TMPDIR" => HOMEBREW_TEMP.to_s,
139+
"TEMP" => HOMEBREW_TEMP.to_s,
140+
"TMP" => HOMEBREW_TEMP.to_s,
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::Array[String]]) }
40+
sig { returns(T::Hash[Symbol, T.nilable(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::Array[String]]))
44+
@skipped_entries ||= T.let({}, T.nilable(T::Hash[Symbol, T.nilable(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: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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])] }
1516
DEFAULT_DIRS = T.let(
1617
{
1718
appdir: "/Applications",
@@ -33,7 +34,8 @@ class Config
3334
T::Hash[Symbol, String],
3435
)
3536

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

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

7274
new(
73-
default: config.fetch("default", {}),
74-
env: config.fetch("env", {}),
75-
explicit: config.fetch("explicit", {}),
75+
default: config.fetch(:default, {}),
76+
env: config.fetch(:env, {}),
77+
explicit: config.fetch(:explicit, {}),
7678
ignore_invalid_keys:,
7779
)
7880
end
7981

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-
}
82+
sig { params(config: ConfigHash).returns(ConfigHash) }
8983
def self.canonicalize(config)
9084
config.to_h do |k, v|
91-
key = k.to_sym
92-
93-
if DEFAULT_DIRS.key?(key)
85+
if DEFAULT_DIRS.key?(k)
9486
raise TypeError, "Invalid path for default dir #{k}: #{v.inspect}" if v.is_a?(Array)
9587

96-
[key, Pathname(v).expand_path]
88+
[k, Pathname(v.to_s).expand_path]
9789
else
98-
[key, v]
90+
[k, v]
9991
end
10092
end
10193
end
10294

10395
# Get the explicit configuration.
10496
#
10597
# @api internal
106-
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
98+
sig { returns(ConfigHash) }
10799
attr_accessor :explicit
108100

109101
sig {
110102
params(
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])],
103+
default: T.nilable(ConfigHash),
104+
env: T.nilable(ConfigHash),
105+
explicit: ConfigHash,
114106
ignore_invalid_keys: T::Boolean,
115107
).void
116108
}
117109
def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false)
118110
if default
119111
@default = T.let(
120112
self.class.canonicalize(self.class.defaults.merge(default)),
121-
T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]),
113+
T.nilable(ConfigHash),
122114
)
123115
end
124116
if env
125117
@env = T.let(
126118
self.class.canonicalize(env),
127-
T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]),
119+
T.nilable(ConfigHash),
128120
)
129121
end
130122
@explicit = T.let(
131123
self.class.canonicalize(explicit),
132-
T::Hash[Symbol, T.any(String, Pathname, T::Array[String])],
124+
ConfigHash,
133125
)
134126

135127
if ignore_invalid_keys
@@ -142,26 +134,26 @@ def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false)
142134
@explicit.assert_valid_keys(*self.class.defaults.keys)
143135
end
144136

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

150-
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
142+
sig { returns(ConfigHash) }
151143
def env
152144
@env ||= self.class.canonicalize(
153145
Homebrew::EnvConfig.cask_opts
154146
.select { |arg| arg.include?("=") }
155147
.map { |arg| T.cast(arg.split("=", 2), [String, String]) }
156-
.map do |(flag, value)|
148+
.to_h do |(flag, value)|
157149
key = flag.sub(/^--/, "")
158150
# converts --language flag to :languages config key
159151
if key == "language"
160152
key = "languages"
161153
value = value.split(",")
162154
end
163155

164-
[key, value]
156+
[key.to_sym, value]
165157
end,
166158
)
167159
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::Hash[String, T.untyped]).void }
14+
sig { params(attributes: T.any(T::Hash[String, T.untyped], T::Hash[Symbol, 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: 3 additions & 2 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[String, String]),
57+
cookies: T.nilable(T::Hash[T.any(String, Symbol), 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,7 +80,8 @@ 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] = @cookies = T.let(cookies, T.nilable(T::Hash[String, String]))
83+
specs[:cookies] =
84+
@cookies = T.let(cookies&.transform_keys(&:to_s), T.nilable(T::Hash[String, String]))
8485
specs[:referer] = @referer = T.let(referer, T.nilable(T.any(URI::Generic, String)))
8586
specs[:headers] = @header = T.let(header, T.nilable(T.any(String, T::Array[String])))
8687
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[CaskDependent::Requirement]) }
48+
sig { returns(T::Array[::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[CaskDependent::Requirement]),
76+
T.nilable(T::Array[::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[[String, T.nilable(String), String, T::Boolean]] }
12+
OptionsType = T.type_alias { T::Array[[T.nilable(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 = long || short
173+
option = T.must(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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def print_outdated(formulae_or_casks)
127127
sig {
128128
params(
129129
formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)],
130-
).returns(
131-
T::Array[T.any(T::Hash[String, T.untyped], T::Hash[String, T.untyped])],
132-
)
130+
).returns(T::Array[T::Hash[Symbol, T.untyped]])
133131
}
134132
def json_info(formulae_or_casks)
135133
formulae_or_casks.map do |formula_or_cask|

Library/Homebrew/cmd/update-report.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,19 @@ 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+
433446
class ReporterRevisionUnsetError < RuntimeError
434447
sig { params(var_name: String).void }
435448
def initialize(var_name)
@@ -459,14 +472,17 @@ def initialize(tap, api_names_txt: nil, api_names_before_txt: nil, api_dir_prefi
459472
raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty?
460473
end
461474

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

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

469-
@report = Hash.new { |h, k| h[k] = [] }
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+
}
470486
return @report unless updated?
471487

472488
diff.each_line do |line|
@@ -794,19 +810,21 @@ class ReporterHub
794810

795811
sig { void }
796812
def initialize
797-
@hash = T.let({}, T::Hash[Symbol, T::Array[String]])
813+
@hash = T.let({}, T::Hash[Symbol, T::Array[T.any(String, [String, String])]])
798814
@reporters = T.let([], T::Array[Reporter])
799815
end
800816

801817
sig { params(key: Symbol).returns(T::Array[String]) }
802818
def select_formula_or_cask(key)
803-
@hash.fetch(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])
804822
end
805823

806824
sig { params(reporter: Reporter, auto_update: T::Boolean).void }
807825
def add(reporter, auto_update: false)
808826
@reporters << reporter
809-
report = reporter.report(auto_update:).delete_if { |_k, v| v.empty? }
827+
report = reporter.report(auto_update:).reject { |_k, v| v.empty? }
810828
@hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
811829
end
812830

0 commit comments

Comments
 (0)