Remove unused instance variables in API code - #23346
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes write-only instance-variable assignments in Homebrew’s API-related code to reduce dead state and keep the API implementation easier to reason about.
Changes:
- Removes unused
@stale_secondsassignments fromHomebrew::API::JSONDownloadStrategyandHomebrew::API::JSONDownload. - Removes unused
@old_homebrew_cellarcapture fromAPIHashable#generating_hash!.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Library/Homebrew/api/json_download.rb | Drops unused @stale_seconds ivars in JSON API download strategy/helper classes. |
| Library/Homebrew/api_hashable.rb | Removes unused @old_homebrew_cellar assignment during API hash generation monkeypatch setup. |
Comments suppressed due to low confidence (1)
Library/Homebrew/api/json_download.rb:42
@targetis assigned but never read (this class delegates the target to the URL specs/downloader). Keeping an unused instance variable here is inconsistent with the PR’s goal of removing write-only ivars.
def initialize(url, target:, stale_seconds:)
super()
@url = T.let(URL.new(url, using: API::JSONDownloadStrategy, target:, stale_seconds:), URL)
@target = target
end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
These instance variables are assigned but never read: - `@stale_seconds` and `@target` in `Homebrew::API::JSONDownloadStrategy` and `Homebrew::API::JSONDownload`; the value is used via `meta[:target]`/ `meta[:stale_seconds]` and the `target`/`stale_seconds` arguments, not the ivars. (`JSONDownloadStrategy#initialize` then only called `super`, so drop it too.) - `@old_homebrew_cellar` in `APIHashable`, which is saved during API generation but never restored (only the prefix, home and git config are). Claude-Session: https://claude.ai/code/session_011BgWRBydtdkvt8ocqH4nj9
dduugg
force-pushed
the
remove-unused-api-ivars
branch
from
July 29, 2026 04:45
f71fb6f to
7e2cd50
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes instance-variable assignments that are never read.
Homebrew::API::JSONDownloadStrategyandHomebrew::API::JSONDownload,@stale_secondsand@targetare assigned ininitializebut never read (not in these classes, nor in theAbstractDownloadStrategyparent orDownloadablemixin). The value is used throughmeta[:target]/meta[:stale_seconds]and thetarget/stale_secondsarguments instead. With both ivars gone,JSONDownloadStrategy#initializeonly calledsuper, so it is removed too.APIHashable#@old_homebrew_cellaris saved ingenerating_hash!but never restored anywhere (only@old_homebrew_prefix,@old_homeand@old_git_config_globalare restored, andHOMEBREW_CELLARis not monkeypatched in the first place).Instance-variable assignments like these aren't reported by
brew deadcode(Spoom models methods and constants, not ivars), which is why they lingered. Verified withgit grepthat nothing reads them.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude (Claude Code) found the initial write-only instance variables (
@stale_seconds,@old_homebrew_cellar) and drafted the removal. The@targetremoval was prompted by Copilot's review. I verified withgit grepthat nothing reads them and ranbrew lgtm(style, typecheck, tests) successfully.