Skip to content

Commit

Permalink
Merge pull request #16183 from dduugg/sorbet-updates
Browse files Browse the repository at this point in the history
Sorbet updates for compatibility with recent releases
  • Loading branch information
MikeMcQuaid authored Nov 6, 2023
2 parents 0373b80 + 57baeb8 commit d4bf3b0
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/relocated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.from_args(cask, *args)
source_string, target_hash = args

if target_hash
raise CaskInvalidError unless target_hash.respond_to?(:keys)
raise CaskInvalidError, cask unless target_hash.respond_to?(:keys)

target_hash.assert_valid_keys(:target)
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def self.canonicalize(config)
key = k.to_sym

if DEFAULT_DIRS.key?(key)
raise TypeError, "Invalid path for default dir #{k}: #{v.inspect}" if v.is_a?(Array)

[key, Pathname(v).expand_path]
else
[key, v]
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def location
def raw_url_line
return @raw_url_line if defined?(@raw_url_line)

@raw_url_line = Pathname(@caller_location.path)
@raw_url_line = Pathname(T.must(@caller_location.path))
.each_line
.drop(@caller_location.lineno - 1)
.first
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def tap_or_untap_core_taps_if_necessary
next unless tap.installed?

if tap.git_branch == "master" &&
(Date.parse(tap.git_repo.last_commit_date) <= Date.today.prev_month)
(Date.parse(T.must(tap.git_repo.last_commit_date)) <= Date.today.prev_month)
ohai "#{tap.name} is old and unneeded, untapping to save space..."
tap.uninstall
else
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def <<(other)
__getobj__.delete(req)
end
end
# see https://sorbet.org/docs/faq#how-can-i-fix-type-errors-that-arise-from-super
T.bind(self, T.untyped)
super
self
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bump-cask-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def bump_cask_pr
sig {
params(
cask: Cask::Cask,
new_hash: T.nilable(String),
new_hash: T.any(NilClass, String, Symbol),
new_version: BumpVersionParser,
replacement_pairs: T::Array[[T.any(Regexp, String), T.any(Regexp, String)]],
).returns(T::Array[[T.any(Regexp, String), T.any(Regexp, String)]])
Expand Down Expand Up @@ -234,7 +234,7 @@ def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
end
elsif new_hash
opoo "Cask contains multiple hashes; only updating hash for current arch." if cask.on_system_blocks_exist?
replacement_pairs << [old_hash.to_s, new_hash]
replacement_pairs << [old_hash.to_s, new_hash.to_s]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def install_p(src, new_basename)
# https://bugs.ruby-lang.org/issues/7707
# In that case, use the system "mv" command.
if src.symlink?
raise unless Kernel.system "mv", src, dst
raise unless Kernel.system "mv", src.to_s, dst
else
FileUtils.mv src, dst
end
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/extend/predicable.rbi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# typed: strict

module Predicable
requires_ancestor { Class }
include Kernel
requires_ancestor { Module }
end
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def full_installed_alias_name

# The path that was specified to find this formula.
def specified_path
default_specified_path = Pathname(alias_path) if alias_path.present?
default_specified_path = Pathname(T.must(alias_path)) if alias_path.present?
default_specified_path ||= @unresolved_path

return default_specified_path if default_specified_path.presence&.exist?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def pour_bottle?(output_warning: false)

unless bottle.compatible_locations?
if output_warning
prefix = Pathname(bottle.cellar).parent
prefix = Pathname(bottle.cellar.to_s).parent
opoo <<~EOS
Building #{formula.full_name} from source as the bottle needs:
- HOMEBREW_CELLAR: #{bottle.cellar} (yours is #{HOMEBREW_CELLAR})
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/language/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def self.pack_for_installation
# fed to `npm install` only symlinks are created linking back to that
# directory, consequently breaking that assumption. We require a tarball
# because npm install creates a "real" installation when fed a tarball.
if (package = Pathname("package.json")) && package.exist?
package = Pathname("package.json")
if package.exist?
begin
pkg_json = JSON.parse(package.read)
rescue JSON::ParserError
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/lazy_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __setobj__(callable)

# Forward to the inner object to make lazy objects type-checkable.
def is_a?(klass)
# see https://sorbet.org/docs/faq#how-can-i-fix-type-errors-that-arise-from-super
T.bind(self, T.untyped)
__getobj__.is_a?(klass) || super
end
end
2 changes: 1 addition & 1 deletion Library/Homebrew/macos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.from_symbol(version)
def initialize(version)
raise MacOSVersion::Error, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version)

super(version)
super(T.must(version))

@comparison_cache = {}
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def compatible_locations?(tag: Utils::Bottles.tag)

return true if RELOCATABLE_CELLARS.include?(cellar)

prefix = Pathname(cellar).parent.to_s
prefix = Pathname(cellar.to_s).parent.to_s

cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/sorbet/parlour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Homebrew
# Parlour type signature generator helper class for Homebrew.
module Parlour
ROOT_DIR = T.let(Pathname(__dir__).parent.realpath.freeze, Pathname).freeze
ROOT_DIR = T.let(Pathname(T.must(__dir__)).parent.realpath.freeze, Pathname).freeze

sig { returns(T::Array[Parser::AST::Node]) }
def self.ast_list
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio

children = tmp_unpack_dir.children

if children.count == 1 && !children.first.directory?
if children.size == 1 && !children.fetch(0).directory?
s = UnpackStrategy.detect(children.first, prioritize_extension: prioritize_extension)

s.extract_nestedly(to: to, verbose: verbose, prioritize_extension: prioritize_extension)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/unversioned_cask_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def all_versions
top_level_info_plist_paths.each(&parse_info_plist)
ensure
Cask::Utils.gain_permissions_remove(extract_dir)
extract_dir.mkpath
Pathname(extract_dir).mkpath
end
end

Expand Down Expand Up @@ -252,7 +252,7 @@ def guess_cask_version
}.uniq
ensure
Cask::Utils.gain_permissions_remove(extract_dir)
extract_dir.mkpath
Pathname(extract_dir).mkpath
end
end

Expand Down
14 changes: 8 additions & 6 deletions Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ def resolve_formula_names(bottle_file)
receipt_file = file_from_bottle(bottle_file, receipt_file_path)
tap = Tab.from_file_content(receipt_file, "#{bottle_file}/#{receipt_file_path}").tap
"#{tap}/#{name}" if tap.present? && !tap.core_tap?
elsif (bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json"))) &&
bottle_json_path.exist? &&
(bottle_json_path_contents = bottle_json_path.read.presence) &&
(bottle_json = JSON.parse(bottle_json_path_contents).presence) &&
bottle_json.is_a?(Hash)
bottle_json.keys.first.presence
else
bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json"))
if bottle_json_path.exist? &&
(bottle_json_path_contents = bottle_json_path.read.presence) &&
(bottle_json = JSON.parse(bottle_json_path_contents).presence) &&
bottle_json.is_a?(Hash)
bottle_json.keys.first.presence
end
end
full_name ||= name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def init
# `sorbet` is available transitively through the `yard-sorbet` plugin, but we're
# outside of the standalone sorbet config, so `checked` is enabled by default
T.bind(self, YARD::Templates::Template, checked: false)
T.bind(self, T.all(Class, YARD::Templates::Template), checked: false)
super

return if sections.empty?
Expand Down

0 comments on commit d4bf3b0

Please sign in to comment.