From c738d5c007d4594a809a79f90331a2aeaf65abc5 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 27 Jul 2025 10:00:26 -0700 Subject: [PATCH] Fix type error in Readall --- Library/Homebrew/on_system.rb | 49 +++++++++++++++++++---------------- Library/Homebrew/readall.rb | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Library/Homebrew/on_system.rb b/Library/Homebrew/on_system.rb index 4e1854ad19..bb36701ad0 100644 --- a/Library/Homebrew/on_system.rb +++ b/Library/Homebrew/on_system.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "simulate_system" @@ -6,15 +6,15 @@ require "simulate_system" module OnSystem ARCH_OPTIONS = [:intel, :arm].freeze BASE_OS_OPTIONS = [:macos, :linux].freeze - ALL_OS_OPTIONS = [*MacOSVersion::SYMBOLS.keys, :linux].freeze - ALL_OS_ARCH_COMBINATIONS = ALL_OS_OPTIONS.product(ARCH_OPTIONS).freeze + ALL_OS_OPTIONS = T.let([*MacOSVersion::SYMBOLS.keys, :linux].freeze, T::Array[Symbol]) + ALL_OS_ARCH_COMBINATIONS = T.let(ALL_OS_OPTIONS.product(ARCH_OPTIONS).freeze, T::Array[[Symbol, Symbol]]) - VALID_OS_ARCH_TAGS = ALL_OS_ARCH_COMBINATIONS.filter_map do |os, arch| + VALID_OS_ARCH_TAGS = T.let(ALL_OS_ARCH_COMBINATIONS.filter_map do |os, arch| tag = Utils::Bottles::Tag.new(system: os, arch:) next unless tag.valid_combination? tag - end.freeze + end.freeze, T::Array[Utils::Bottles::Tag]) sig { params(arch: Symbol).returns(T::Boolean) } def self.arch_condition_met?(arch) @@ -55,11 +55,11 @@ module OnSystem method_name.to_s.sub(/^on_/, "").to_sym end - sig { params(base: Class).void } + sig { params(base: T::Class[T.anything]).void } def self.setup_arch_methods(base) ARCH_OPTIONS.each do |arch| base.define_method(:"on_#{arch}") do |&block| - @on_system_blocks_exist = true + @on_system_blocks_exist = T.let(true, T.nilable(TrueClass)) return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(T.must(__method__)) @@ -72,7 +72,7 @@ module OnSystem end base.define_method(:on_arch_conditional) do |arm: nil, intel: nil| - @on_system_blocks_exist = true + @on_system_blocks_exist = T.let(true, T.nilable(TrueClass)) if OnSystem.arch_condition_met? :arm arm @@ -82,11 +82,11 @@ module OnSystem end end - sig { params(base: Class).void } + sig { params(base: T::Class[T.anything]).void } def self.setup_base_os_methods(base) BASE_OS_OPTIONS.each do |base_os| base.define_method(:"on_#{base_os}") do |&block| - @on_system_blocks_exist = true + @on_system_blocks_exist = T.let(true, T.nilable(TrueClass)) return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(T.must(__method__)) @@ -99,7 +99,7 @@ module OnSystem end base.define_method(:on_system) do |linux, macos:, &block| - @on_system_blocks_exist = true + @on_system_blocks_exist = T.let(true, T.nilable(TrueClass)) raise ArgumentError, "The first argument to `on_system` must be `:linux`" if linux != :linux @@ -118,7 +118,7 @@ module OnSystem end base.define_method(:on_system_conditional) do |macos: nil, linux: nil| - @on_system_blocks_exist = true + @on_system_blocks_exist = T.let(true, T.nilable(TrueClass)) if OnSystem.os_condition_met?(:macos) && macos.present? macos @@ -128,21 +128,24 @@ module OnSystem end end - sig { params(base: Class).void } + sig { params(base: T::Class[T.anything]).void } def self.setup_macos_methods(base) MacOSVersion::SYMBOLS.each_key do |os_name| base.define_method(:"on_#{os_name}") do |or_condition = nil, &block| - @on_system_blocks_exist = true + @on_system_blocks_exist = T.let(true, T.nilable(TrueClass)) os_condition = OnSystem.condition_from_method_name T.must(__method__) return unless OnSystem.os_condition_met? os_condition, or_condition - @on_system_block_min_os = if or_condition == :or_older - @called_in_on_system_block ? @on_system_block_min_os : MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) - else - MacOSVersion.from_symbol(os_condition) - end - @called_in_on_system_block = true + @on_system_block_min_os = T.let( + if or_condition == :or_older + @called_in_on_system_block ? @on_system_block_min_os : MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) + else + MacOSVersion.from_symbol(os_condition) + end, + T.nilable(MacOSVersion), + ) + @called_in_on_system_block = T.let(true, T.nilable(T::Boolean)) result = block.call @called_in_on_system_block = false @@ -151,13 +154,13 @@ module OnSystem end end - sig { params(_base: Class).void } + sig { params(_base: T::Class[T.anything]).void } def self.included(_base) raise "Do not include `OnSystem` directly. Instead, include `OnSystem::MacOSAndLinux` or `OnSystem::MacOSOnly`" end module MacOSAndLinux - sig { params(base: Class).void } + sig { params(base: T::Class[T.anything]).void } def self.included(base) OnSystem.setup_arch_methods(base) OnSystem.setup_base_os_methods(base) @@ -166,7 +169,7 @@ module OnSystem end module MacOSOnly - sig { params(base: Class).void } + sig { params(base: T::Class[T.anything]).void } def self.included(base) OnSystem.setup_arch_methods(base) OnSystem.setup_macos_methods(base) diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 363fad0d29..36ae737fcf 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -90,7 +90,7 @@ module Readall sig { params( - tap: Tap, aliases: T::Boolean, no_simulate: T::Boolean, os_arch_combinations: T::Array[T::Array[String]], + tap: Tap, aliases: T::Boolean, no_simulate: T::Boolean, os_arch_combinations: T::Array[[Symbol, Symbol]], ).returns(T::Boolean) } def self.valid_tap?(tap, aliases: false, no_simulate: false,