Skip to content

Replace some T.nilable(T::Boolean) - #23350

Open
botantony wants to merge 1 commit into
mainfrom
remove-nilable-booleans
Open

Replace some T.nilable(T::Boolean)#23350
botantony wants to merge 1 commit into
mainfrom
remove-nilable-booleans

Conversation

@botantony

Copy link
Copy Markdown
Member

Most of the times nilable booleans are useless as nil and false serve the same role


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Copilot AI review requested due to automatic review settings July 29, 2026 13:23

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Hold for now until you've done audit and ideally @samford and others have chimed in.

Comment on lines -89 to -90
show_output: T.nilable(T::Boolean),
show_error: T.nilable(T::Boolean),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure these cases (CC @samford) as specifically tri-state to differentiate between:

  • set true by caller
  • set false by caller
  • unset by caller

I don't think this tri-state is likely needed/desired in literally every case you've modified here but it would be good to do a careful audit of each one to consider that.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens Sorbet type signatures by replacing several T.nilable(T::Boolean) usages with stricter boolean types and corresponding default values/return contracts, aiming to reduce unnecessary tri-state boolean semantics across Homebrew internals.

Changes:

  • Tighten boolean keyword-argument and attribute signatures across utils, livecheck, tab, context, and auditing/installer code.
  • Adjust method defaults/return values to match stricter boolean types (and update a few call-site conditionals accordingly).
  • Update specs to reflect the new typing/argument expectations.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Library/Homebrew/utils/pypi.rb Tightens boolean params/return types for PyPI resource updating and adjusts early returns.
Library/Homebrew/utils/curl.rb Tightens boolean params for curl helpers and changes debug/verbose defaults.
Library/Homebrew/utils/cpan.rb Tightens boolean params/return type for CPAN resource updating.
Library/Homebrew/test/utils/curl_spec.rb Removes coverage for passing nil where show_output is now a boolean.
Library/Homebrew/test/livecheck_spec.rb Updates expectations for invalid compressed/homebrew_curl arguments.
Library/Homebrew/tab/tab.rb Makes poured_from_bottle/built_as_bottle non-nilable booleans and adjusts initialization.
Library/Homebrew/tab.rb Makes loaded_from_api/loaded_from_internal_api non-nilable booleans and adjusts initialization.
Library/Homebrew/livecheck.rb Narrows accepted option types for compressed/homebrew_curl and removes explicit validation.
Library/Homebrew/git_repository.rb Tightens return type of default_origin_branch? to boolean.
Library/Homebrew/formula_installer.rb Tightens fresh_install? return type to boolean.
Library/Homebrew/formula_auditor.rb Tightens boolean params and provides explicit boolean defaults.
Library/Homebrew/extend/os/mac/formula_installer.rb Tightens fresh_install? return type to boolean in macOS extension.
Library/Homebrew/dev-cmd/bump-formula-pr.rb Adjusts resource-checked condition to treat falsy values uniformly.
Library/Homebrew/dev-cmd/bottle.rb Changes sudo_purge signature and return behaviour.
Library/Homebrew/context.rb Makes context booleans non-nilable and simplifies predicate methods.
Comments suppressed due to low confidence (2)

Library/Homebrew/livecheck.rb:215

  • The removal of explicit validation for compressed/homebrew_curl changes runtime behaviour when Sorbet runtime checks are disabled (the default; T.sig is a no-op). Calls like compressed: true or homebrew_curl: false will now silently apply invalid values instead of raising, which also makes the updated spec expectations unreliable.
    raise ArgumentError, "Only use `post_form` or `post_json`, not both" if post_form && post_json

    @options.compressed = compressed unless compressed.nil?
    @options.cookies = cookies unless cookies.nil?
    @options.header = header unless header.nil?
    @options.homebrew_curl = homebrew_curl unless homebrew_curl.nil?

Library/Homebrew/dev-cmd/bottle.rb:321

  • sudo_purge is now declared as sig { void } but returns booleans (false or the result of system). Either the sig should return a boolean or the method should return nil when disabled, to match the signature and avoid confusing call sites.
      sig { void }
      def sudo_purge
        return unless ENV["HOMEBREW_BOTTLE_SUDO_PURGE"]

        system "/usr/bin/sudo", "--non-interactive", "/usr/sbin/purge"

馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/test/livecheck_spec.rb Outdated
Comment thread Library/Homebrew/utils/pypi.rb
Comment thread Library/Homebrew/utils/curl.rb Outdated
@botantony
botantony marked this pull request as draft July 29, 2026 13:31
@botantony
botantony force-pushed the remove-nilable-booleans branch from f00ba56 to f462ee4 Compare July 29, 2026 14:18
Comment thread Library/Homebrew/livecheck.rb
@botantony
botantony force-pushed the remove-nilable-booleans branch from f462ee4 to 8872428 Compare August 4, 2026 12:15
@botantony
botantony marked this pull request as ready for review August 4, 2026 12:15
@botantony
botantony force-pushed the remove-nilable-booleans branch from 8872428 to 6d0106d Compare August 4, 2026 12:16
Most of the times nilable booleans are useless as `nil` and `false`
serve the same role

Signed-off-by: botantony <antonsm21@gmail.com>
@botantony
botantony force-pushed the remove-nilable-booleans branch from 6d0106d to 513604a Compare August 4, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants