From b5d07dd7d68b849def8a613a268deab5fa132b94 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 11 Feb 2024 10:08:44 -0800 Subject: [PATCH 1/2] Finalize methods that do not support overrides --- Library/Homebrew/requirement.rb | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 0d5f1df7e3..2fa22bb4f7 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -61,8 +61,15 @@ class Requirement s end - # Overriding {#satisfied?} is unsupported. - # Pass a block or boolean to the satisfy DSL method instead. + # Pass a block or boolean to the satisfy DSL method instead of overriding. + sig(:final) { + params( + env: T.nilable(String), + cc: T.nilable(String), + build_bottle: T::Boolean, + bottle_arch: T.nilable(String), + ).returns(T::Boolean) + } def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil) satisfy = self.class.satisfy return true unless satisfy @@ -76,8 +83,8 @@ class Requirement true end - # Overriding {#fatal?} is unsupported. - # Pass a boolean to the fatal DSL method instead. + # Pass a boolean to the fatal DSL method instead of overriding. + sig(:final) { returns(T::Boolean) } def fatal? self.class.fatal || false end @@ -92,8 +99,15 @@ class Requirement parent end - # Overriding {#modify_build_environment} is unsupported. - # Pass a block to the env DSL method instead. + # Pass a block to the env DSL method instead of overriding. + sig(:final) { + params( + env: T.nilable(String), + cc: T.nilable(String), + build_bottle: T::Boolean, + bottle_arch: T.nilable(String), + ).returns(T.untyped) + } def modify_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil) satisfied?(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) instance_eval(&env_proc) if env_proc From e7e4ecc4051dfe6e217aa76c9d93b4c86677a7d9 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 19 Feb 2024 13:29:49 -0800 Subject: [PATCH 2/2] Change return type --- Library/Homebrew/requirement.rb | 2 +- Library/Homebrew/test/requirement_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 2fa22bb4f7..d4d15b4f69 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -106,7 +106,7 @@ class Requirement cc: T.nilable(String), build_bottle: T::Boolean, bottle_arch: T.nilable(String), - ).returns(T.untyped) + ).void } def modify_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil) satisfied?(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 7b578004ed..f1a684e353 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -177,7 +177,7 @@ RSpec.describe Requirement do let(:klass) { Class.new(described_class) } it "returns nil" do - expect(requirement.modify_build_environment).to be_nil + expect { requirement.modify_build_environment }.not_to raise_error end end end