Skip to content

Commit 8bf6846

Browse files
authored
Revert "sorbet: upgrade remaining 19 files to typed: strict"
1 parent a135f04 commit 8bf6846

81 files changed

Lines changed: 611 additions & 1570 deletions

Some content is hidden

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

Library/Homebrew/attestation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def self.sort_formulae_for_install(formulae)
120120
# @api private
121121
sig {
122122
params(bottle: Bottle, signing_repo: String,
123-
signing_workflow: T.nilable(String), subject: T.nilable(String)).returns(T::Hash[String, T.untyped])
123+
signing_workflow: T.nilable(String), subject: T.nilable(String)).returns(T::Hash[T.untyped, T.untyped])
124124
}
125125
def self.check_attestation(bottle, signing_repo, signing_workflow = nil, subject = nil)
126126
cmd = ["attestation", "verify", bottle.cached_download, "--repo", signing_repo, "--format",
@@ -138,12 +138,12 @@ def self.check_attestation(bottle, signing_repo, signing_workflow = nil, subject
138138
env: { "GH_TOKEN" => credentials, "GH_HOST" => "github.com" },
139139
secrets: [credentials], print_stderr: false, chdir: HOMEBREW_TEMP)
140140
rescue ErrorDuringExecution => e
141-
if e.exitstatus == 1 && e.stderr.include?("unknown command")
141+
if e.status.exitstatus == 1 && e.stderr.include?("unknown command")
142142
raise GhIncompatible, "gh CLI is incompatible with attestations"
143143
end
144144

145145
# Even if we have credentials, they may be invalid or malformed.
146-
if e.exitstatus == 4 || e.stderr.include?("HTTP 401: Bad credentials")
146+
if e.status.exitstatus == 4 || e.stderr.include?("HTTP 401: Bad credentials")
147147
raise GhAuthInvalid, "invalid credentials"
148148
end
149149

@@ -205,7 +205,7 @@ def self.check_attestation(bottle, signing_repo, signing_workflow = nil, subject
205205
# @raise [InvalidAttestationError] on any verification failures
206206
#
207207
# @api private
208-
sig { params(bottle: Bottle).returns(T::Hash[String, T.untyped]) }
208+
sig { params(bottle: Bottle).returns(T::Hash[T.untyped, T.untyped]) }
209209
def self.check_core_attestation(bottle)
210210
begin
211211
# Ideally, we would also constrain the signing workflow here, but homebrew-core

Library/Homebrew/bottle.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def installed_size
194194

195195
sig { returns(Filename) }
196196
def filename
197-
Filename.create(T.cast(resource.owner, Formula), @tag, @spec.rebuild)
197+
Filename.create(resource.owner, @tag, @spec.rebuild)
198198
end
199199

200200
sig { returns(T.nilable(Resource::BottleManifest)) }
@@ -259,7 +259,7 @@ def root_url(val = nil, specs = {})
259259

260260
@root_url = T.let(val, T.nilable(String))
261261

262-
filename = Filename.create(T.cast(resource.owner, Formula), @tag, @spec.rebuild)
262+
filename = Filename.create(resource.owner, @tag, @spec.rebuild)
263263
resource_checksum = resource.checksum
264264
odie "resource checksum is nil" if resource_checksum.nil?
265265

Library/Homebrew/brew.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@
163163
#{Formatter.bold("Do not report any issues to Homebrew/* repositories!")}
164164
Read the above document instead before opening any issues or PRs.
165165
EOS
166-
elsif (formula = e.formula) && (formula.head? || formula.deprecated? || formula.disabled?)
167-
reason = if formula.head?
166+
elsif e.formula.head? || e.formula.deprecated? || e.formula.disabled?
167+
reason = if e.formula.head?
168168
"was built from an unstable upstream --HEAD"
169-
elsif formula.deprecated?
169+
elsif e.formula.deprecated?
170170
"is deprecated"
171-
elsif formula.disabled?
171+
elsif e.formula.disabled?
172172
"is disabled"
173173
end
174174
$stderr.puts <<~EOS
175-
#{formula.name}'s formula #{reason}.
175+
#{e.formula.name}'s formula #{reason}.
176176
This build failure is expected behaviour.
177177
EOS
178178
end

Library/Homebrew/build.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def expand_reqs
6969
sig { returns(T::Array[Dependency]) }
7070
def expand_deps
7171
formula.recursive_dependencies do |dependent, dep|
72-
build = effective_build_options_for(T.cast(dependent, Formula))
72+
build = effective_build_options_for(dependent)
7373
if dep.prune_from_option?(build) ||
74-
dep.prune_if_build_and_not_dependent?(T.cast(dependent, Formula), formula) ||
74+
dep.prune_if_build_and_not_dependent?(dependent, formula) ||
7575
(dep.test? && !dep.build?) || dep.implicit?
7676
Dependency.prune
7777
elsif dep.build?
@@ -291,8 +291,8 @@ def normalize_pod2man_outputs!(formula)
291291
error_hash["cmd"] = e.cmd
292292
error_hash["status"] = if e.status.is_a?(Process::Status)
293293
{
294-
exitstatus: e.exitstatus,
295-
termsig: e.termsig,
294+
exitstatus: e.status.exitstatus,
295+
termsig: e.status.termsig,
296296
}
297297
else
298298
e.status

Library/Homebrew/build_environment.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ def env(*settings)
5959
].freeze
6060
private_constant :KEYS
6161

62-
sig { params(env: T::Hash[String, T.nilable(T.any(String, T::Boolean, PATH))]).returns(T::Array[String]) }
62+
sig { params(env: T::Hash[String, T.nilable(T.any(String, Pathname))]).returns(T::Array[String]) }
6363
def self.keys(env)
6464
KEYS & env.keys
6565
end
6666

67-
sig { params(env: T::Hash[String, T.nilable(T.any(String, T::Boolean, PATH))], out: IO).void }
67+
sig { params(env: T::Hash[String, T.nilable(T.any(String, Pathname))], out: IO).void }
6868
def self.dump(env, out = $stdout)
6969
keys = self.keys(env)
7070
keys -= %w[CC CXX OBJC OBJCXX] if env["CC"] == env["HOMEBREW_CC"]
@@ -75,7 +75,6 @@ def self.dump(env, out = $stdout)
7575
string = "#{key}: #{value}"
7676
case key
7777
when "CC", "CXX", "LD"
78-
value = T.cast(value, String)
7978
string << " => #{Pathname.new(value).realpath}" if value.present? && File.symlink?(value)
8079
end
8180
string.freeze

Library/Homebrew/build_options.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(args, options)
3030
# args << "--with-example1"
3131
# end
3232
# ```
33-
sig { params(val: T.any(String, Dependable)).returns(T::Boolean) }
33+
sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) }
3434
def with?(val)
3535
option_names = if val.is_a?(String)
3636
[val]
@@ -56,7 +56,7 @@ def with?(val)
5656
# ```ruby
5757
# args << "--no-spam-plz" if build.without? "spam"
5858
# ```
59-
sig { params(val: T.any(String, Dependable)).returns(T::Boolean) }
59+
sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) }
6060
def without?(val)
6161
!with?(val)
6262
end

Library/Homebrew/bundle.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ def mark_as_installed_on_request!(entries)
140140
next if installed_formulae.exclude?(name)
141141

142142
tab = Tab.for_name(name)
143-
tabfile = tab.tabfile
144-
next if tabfile.blank? || !tabfile.exist?
143+
next if tab.tabfile.blank? || !tab.tabfile.exist?
145144
next if tab.installed_on_request
146145

147146
next name if use_brew_tab

Library/Homebrew/bundle/brew.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ def formula_to_hash(formula)
287287
installed_as_dependency = tab.installed_as_dependency
288288
installed_on_request = tab.installed_on_request
289289
runtime_dependencies = if (runtime_deps = tab.runtime_dependencies)
290-
T.cast(runtime_deps, T::Array[T::Hash[String, T.untyped]]).filter_map { |d| d["full_name"] }
290+
runtime_deps.filter_map { |d| d["full_name"] }
291+
291292
end
292293
poured_from_bottle = tab.poured_from_bottle
293294
end

Library/Homebrew/cache_store.rb

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@
88
# residing in the `HOMEBREW_CACHE`.
99
#
1010
class CacheStoreDatabase
11-
extend T::Generic
12-
13-
# Sorbet type members are mutable by design and cannot be frozen.
14-
Key = type_member # rubocop:disable Style/MutableConstant
15-
# Sorbet type members are mutable by design and cannot be frozen.
16-
Value = type_member # rubocop:disable Style/MutableConstant
17-
1811
# Yields the cache store database.
1912
# Closes the database after use if it has been loaded.
13+
#
14+
# @param [Symbol] type
15+
# @yield [CacheStoreDatabase] self
2016
sig {
2117
type_parameters(:U)
2218
.params(
2319
type: Symbol,
24-
_blk: T.proc.params(arg0: CacheStoreDatabase[T.anything, T.anything]).returns(T.type_parameter(:U)),
20+
_blk: T.proc.params(arg0: CacheStoreDatabase).returns(T.type_parameter(:U)),
2521
)
2622
.returns(T.type_parameter(:U))
2723
}
@@ -51,29 +47,32 @@ def self.use(type, &_blk)
5147
end
5248

5349
# Creates a CacheStoreDatabase.
50+
#
51+
# @param [Symbol] type
52+
# @return [nil]
5453
sig { params(type: Symbol).void }
5554
def initialize(type)
5655
@type = type
5756
@dirty = T.let(false, T.nilable(T::Boolean))
5857
end
5958

6059
# Sets a value in the underlying database (and creates it if necessary).
61-
sig { params(key: Key, value: Value).void }
60+
sig { params(key: T.anything, value: T.anything).void }
6261
def set(key, value)
6362
dirty!
6463
db[key] = value
6564
end
6665

6766
# Gets a value from the underlying database (if it already exists).
68-
sig { params(key: Key).returns(T.nilable(Value)) }
67+
sig { params(key: T.anything).returns(T.untyped) }
6968
def get(key)
7069
return unless created?
7170

7271
db[key]
7372
end
7473

7574
# Deletes a value from the underlying database (if it already exists).
76-
sig { params(key: Key).void }
75+
sig { params(key: T.anything).void }
7776
def delete(key)
7877
return unless created?
7978

@@ -100,12 +99,16 @@ def write_if_dirty!
10099
end
101100

102101
# Returns `true` if the cache file has been created for the given `@type`.
102+
#
103+
# @return [Boolean]
103104
sig { returns(T::Boolean) }
104105
def created?
105106
cache_path.exist?
106107
end
107108

108109
# Returns the modification time of the cache file (if it already exists).
110+
#
111+
# @return [Time]
109112
sig { returns(T.nilable(Time)) }
110113
def mtime
111114
return unless created?
@@ -114,23 +117,25 @@ def mtime
114117
end
115118

116119
# Performs a `select` on the underlying database.
117-
sig {
118-
overridable.params(block: T.proc.params(arg0: Key, arg1: Value).returns(BasicObject)).returns(T::Hash[Key, Value])
119-
}
120+
#
121+
# @return [Hash]
122+
sig { params(block: T.proc.params(arg0: T.untyped, arg1: T.untyped).returns(BasicObject)).returns(T::Hash[T.untyped, T.untyped]) }
120123
def select(&block)
121124
db.select(&block)
122125
end
123126

124127
# Returns `true` if the cache is empty.
128+
#
129+
# @return [Boolean]
125130
sig { returns(T::Boolean) }
126131
def empty?
127132
db.empty?
128133
end
129134

130135
# Performs a `each_key` on the underlying database.
131-
sig {
132-
params(block: T.proc.params(arg0: Key).returns(BasicObject)).returns(T::Hash[Key, Value])
133-
}
136+
#
137+
# @return [Hash]
138+
sig { params(block: T.proc.params(arg0: T.untyped).returns(BasicObject)).returns(T::Hash[T.untyped, T.untyped]) }
134139
def each_key(&block)
135140
db.each_key(&block)
136141
end
@@ -140,9 +145,11 @@ def each_key(&block)
140145
# Lazily loaded database in read/write mode. If this method is called, a
141146
# database file will be created in the `HOMEBREW_CACHE` with a name
142147
# corresponding to the `@type` instance variable.
143-
sig { returns(T::Hash[Key, Value]) }
148+
#
149+
# @return [Hash] db
150+
sig { returns(T::Hash[T.untyped, T.untyped]) }
144151
def db
145-
@db ||= T.let({}, T.nilable(T::Hash[Key, Value]))
152+
@db ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
146153
return @db if !@db.empty? || !created?
147154

148155
begin
@@ -156,6 +163,8 @@ def db
156163

157164
# The path where the database resides in the `HOMEBREW_CACHE` for the given
158165
# `@type`.
166+
#
167+
# @return [Pathname]
159168
sig { returns(Pathname) }
160169
def cache_path
161170
HOMEBREW_CACHE/"#{@type}.json"
@@ -168,6 +177,8 @@ def dirty!
168177
end
169178

170179
# Returns `true` if the cache needs to be written to disk.
180+
#
181+
# @return [Boolean]
171182
sig { returns(T::Boolean) }
172183
def dirty?
173184
!!@dirty
@@ -179,23 +190,20 @@ def dirty?
179190
# storage mechanism.
180191
#
181192
class CacheStore # rubocop:todo Style/OneClassPerFile
182-
extend T::Generic
183193
extend T::Helpers
184194

185195
abstract!
186196

187-
# Sorbet type members are mutable by design and cannot be frozen.
188-
Key = type_member # rubocop:disable Style/MutableConstant
189-
# Sorbet type members are mutable by design and cannot be frozen.
190-
Value = type_member # rubocop:disable Style/MutableConstant
191-
192-
sig { params(database: CacheStoreDatabase[Key, Value]).void }
197+
# @param [CacheStoreDatabase] database
198+
# @return [nil]
199+
sig { params(database: CacheStoreDatabase).void }
193200
def initialize(database)
194201
@database = database
195202
end
196203

197204
protected
198205

199-
sig { returns(CacheStoreDatabase[Key, Value]) }
206+
# @return [CacheStoreDatabase]
207+
sig { returns(CacheStoreDatabase) }
200208
attr_reader :database
201209
end

Library/Homebrew/cask/dsl/depends_on.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ def macos=(*args)
8181
elsif first_arg.is_a?(Symbol) && MacOSVersion::SYMBOLS.key?(first_arg)
8282
MacOSRequirement.new([args.first], comparator: "==")
8383
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/.match(first_arg_s))
84-
# The named capture groups must exist, so we use T.must to assert that they do.
85-
MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: T.must(md[:comparator]))
84+
MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: md[:comparator])
8685
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*(?<version>\S+)\s*$/.match(first_arg_s))
87-
# The named capture groups must exist, so we use T.must to assert that they do.
88-
MacOSRequirement.new([md[:version]], comparator: T.must(md[:comparator]))
86+
MacOSRequirement.new([md[:version]], comparator: md[:comparator])
8987
# This is not duplicate of the first case: see `args.first` and a different comparator.
9088
else # rubocop:disable Lint/DuplicateBranch
9189
MacOSRequirement.new([args.first], comparator: "==")

0 commit comments

Comments
 (0)