services: fix timed? and keep_alive? return type to T::Boolean#21950
services: fix timed? and keep_alive? return type to T::Boolean#21950hyuraku wants to merge 3 commits intoHomebrew:mainfrom
timed? and keep_alive? return type to T::Boolean#21950Conversation
…and keep_alive? methods
There was a problem hiding this comment.
Pull request overview
This PR updates Homebrew::Services::FormulaWrapper#timed? and #keep_alive? to always return T::Boolean (returning false when no service exists) and aligns the corresponding specs and to_hash expectations.
Changes:
- Change
timed?andkeep_alive?Sorbet signatures fromT.nilable(T::Boolean)toT::Booleanand returnfalsewhenservice?is falsey. - Update service wrapper specs to expect
false(notnil) when no service is present. - Update
to_hashexpectations soschedulableisfalseinstead ofnilfor non-service formulas.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
Library/Homebrew/services/formula_wrapper.rb |
Makes timed? / keep_alive? return false when no service, matching T::Boolean signatures. |
Library/Homebrew/test/services/formula_wrapper_spec.rb |
Adjusts specs (including schedulable) to reflect the new boolean return behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @timed ||= T.let( | ||
| if service? | ||
| load_service.timed? | ||
| else | ||
| false | ||
| end, T.nilable(T::Boolean) | ||
| ) |
There was a problem hiding this comment.
@timed ||= ... will re-run the block whenever the computed value is false (Ruby ||= doesn’t memoize falsey values). This means load_service.timed? (and service?) can be evaluated multiple times for non-timed services, including within a single to_hash call (it calls timed? for schedulable and again via status_symbol). Consider memoizing with a nil sentinel instead (e.g., initialize @timed as T.nilable(T::Boolean) and only compute when it’s nil).
| @keep_alive ||= T.let( | ||
| if service? | ||
| load_service.keep_alive? | ||
| else | ||
| false | ||
| end, T.nilable(T::Boolean) | ||
| ) |
There was a problem hiding this comment.
@keep_alive ||= ... has the same ||= memoization issue: if load_service.keep_alive? returns false, this will recompute on every call, potentially re-loading the service repeatedly. Prefer memoizing with a nil sentinel so both true and false are cached.
| @timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean)) | ||
| T.must(@timed) |
There was a problem hiding this comment.
| @timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean)) | |
| T.must(@timed) | |
| @timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean)) |
don't use T.must here, instead us if or || to ensure the result is always true or false
| return @keep_alive unless @keep_alive.nil? | ||
|
|
||
| @keep_alive = T.let(service? && load_service.keep_alive?, T.nilable(T::Boolean)) | ||
| T.must(@keep_alive) |
brew lgtm(style, typechecking and tests) with your changes locally?solve
brew/Library/Homebrew/services/formula_wrapper.rb
Line 53 in ac782bc
T.nilable(T::Boolean)toT::Boolean