Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: inline use of attr_predicate #19371

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Conversation

dduugg
Copy link
Member

@dduugg dduugg commented Feb 25, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

The follow-up to #19359 which removes remaining use of the Attrable module. This may be less desirable, as it's used more extensively (n = ~50) and it already had correctly compiled sigs.

The defined method for an attr_predicate :foo was @foo == true, but I was able to reduce this to being provably equivalent to just returning @foo in all but two cases (both involving metaprogramming in Formula, which would require a larger refactor to fix). This was possible due to additional refactoring that replaced nil passing with false values instead, but tests seem to indicate that was a valid change.

Using endless defs for these simple methods make this a net removal of >100 LoC, even with the introduction new sigs, so that hopefully atones for the loss of conciseness of attr_predicate. (There is additional upside in not requiring new code readers to learn this brew-specific abstraction, IMO.)

With apologies for the scope creep in this PR, I was also able to promote a few files to typed: strict in this change set. I'm happy to decompose into separate PRs at a reviewer's request.

@dduugg
Copy link
Member Author

dduugg commented Feb 25, 2025

Hmm

# For switches, we add `|| nil` so that `nil` will be passed
# instead of `false` if they aren't set.
# This way, we can distinguish between "not set" and "set to false".
audit_online: args.online? || nil,
audit_strict: args.strict? || nil,
# No need for `|| nil` for `--[no-]signing`
# because boolean switches are already `nil` if not passed
audit_signing: args.signing?,
audit_new_cask: args.new? || nil,
audit_token_conflicts: args.token_conflicts? || nil,
seems to indicate the nil/false distinction matters, in which case i'd need to revert a chunk of this, and stick with @foo == true or !!@foo instead of the simpler @foo for the inlined methods. Sadness.

@dduugg dduugg marked this pull request as draft February 25, 2025 02:29
@dduugg
Copy link
Member Author

dduugg commented Feb 25, 2025

Found the rationale for this distinction: #12375 (comment)

@dduugg dduugg force-pushed the no-attr_predicate branch 2 times, most recently from 3a81bdf to ebdd11f Compare February 25, 2025 03:02
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

I went into this skeptical but: yeh, I prefer this, particularly now we have some Sorbet guarantees. Nice work @dduugg!

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.

2 participants