sorbet: remove redundant T.let in initialize methods#21990
Merged
Conversation
563ebcb to
8cec91c
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes redundant T.let calls in initialize methods where instance variables are assigned directly from Sorbet-sig-typed parameters of the same type, relying on Sorbet’s inference to keep ivar types accurate in typed: strict files.
Changes:
- Replaced
@ivar = T.let(param, <same-type>)with@ivar = paramacross multiple constructors. - Kept
T.letwhere it’s still needed (e.g., nil-initialization / conditional assignment / nontrivial assignment patterns), and only simplified the straightforward cases. - Ran typechecking/style verification per PR description (no behavioral changes intended).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Library/Homebrew/unpack_strategy.rb | Removes redundant T.let for @ref_type/@ref assigned from sig-typed params. |
| Library/Homebrew/patch.rb | Simplifies ivar assignments in patch-related constructors where params are sig-typed. |
| Library/Homebrew/migrator.rb | Removes redundant T.let for @oldname and @formula assigned from typed params. |
| Library/Homebrew/mcp_server.rb | Simplifies @stdin/@stdout/@stderr assignments from sig-typed keyword params. |
| Library/Homebrew/linkage_cache_store.rb | Removes redundant T.let for @keg_path assigned from typed param. |
| Library/Homebrew/formula.rb | Drops redundant T.let for @tap assigned from a nilable Tap param. |
| Library/Homebrew/download_strategy.rb | Simplifies @cached_location and @version assignments from typed params. |
| Library/Homebrew/context.rb | Removes redundant T.let for nilable boolean context flags assigned from typed params. |
| Library/Homebrew/cask/installer.rb | Simplifies @defer_fetch assignment from a T::Boolean param. |
| Library/Homebrew/cask/exceptions.rb | Removes redundant T.let for @errors assigned from typed param. |
| Library/Homebrew/cask/dsl/container.rb | Simplifies nilable @nested/@type assignments from typed keyword params. |
| Library/Homebrew/cask/dsl/base.rb | Removes redundant T.let for @command assigned from typed param. |
| Library/Homebrew/cask/dsl.rb | Removes redundant T.let for @cask assigned from typed param. |
| Library/Homebrew/cask/artifact/manpage.rb | Simplifies @section assignment from typed param. |
| Library/Homebrew/cask/artifact/generated_completion.rb | Removes redundant T.let for several ivars assigned from typed params. |
| Library/Homebrew/cache_store.rb | Simplifies @type and @database assignments from typed params. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Remove
T.letcalls ininitializemethods where the ivar is assigned directly from a sig-typed parameter with an identical type. Sorbet already infers the ivar type from the sig, so theT.letis redundant.16 files affected. Cases where
T.letis still required were left untouched:specs[:x] = @x = T.let(...)) incask/url.rb— Sorbet requires explicitT.letfor ivars intyped: strictherelocale.rb,cmd/update-report.rb) —T.letsets the nilable typeformula_installer.rb)Verified with
brew typecheckandbrew style --fix --changed.Have you written new tests (excluding integration tests) for your changes?(no behaviour change)brew lgtm(style, typechecking and tests) with your changes locally?brew typecheck(which autocorrected one file whereT.letis still required).