forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify type parameters for
Gem::Version
(dependabot#9232)
The upstream types for `Gem::Version.initialize` and `Gem::Version.new` are quite complex. They accept `T.any(String, Integer, Float, Gem::Version, NilClass)`. For our use cases, these are too broad, and we see some issues with `SystemStackError` due to Sorbet's runtime type checking inserted at each level of our class hierarchy i.e. `Ecosystem::Version` -> `Dependabot::Version` -> `Gem::Version`. Sorbet does have documentation on how to [narrow the types of a child method][1]. The documentation suggests altering the parent class to be generic, and specifying the generic type in child classes. Unfortunately, it's not feasible to alter the root class, `Gem::Version`. Another approach might be to use one of Sorbet's escape hatches `override(allow_incompatible: true)`[^3]. But this disables the type checking entirely, and might hide other issues. The approach I'm taking in this change is to instead write our own shim to override the accepted types. [^1]: https://github.com/sorbet/sorbet/blob/15df026a4ffe45871809885a26142bddac5cbdde/rbi/stdlib/rubygems.rbi#L2635-L2646 [^2]: https://github.com/sorbet/sorbet/blob/15df026a4ffe45871809885a26142bddac5cbdde/rbi/stdlib/rubygems.rbi#L2738-L2749 [^3]: https://sorbet.org/docs/override-checking#use-overrideallow_incompatible-true [1]: https://sorbet.org/docs/override-checking#what-if-i-really-want-the-child-method-to-narrow-the-type Co-authored-by: AbdulFattaah Popoola <abdulapopoola@github.com>
- Loading branch information
1 parent
4c75356
commit 0661469
Showing
7 changed files
with
71 additions
and
173 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
module Gem | ||
class Version | ||
sig do | ||
params( | ||
version: T.nilable( | ||
T.any( | ||
String, | ||
Integer, | ||
Gem::Version | ||
) | ||
) | ||
) | ||
.returns(Gem::Version) | ||
end | ||
def self.new(version); end | ||
|
||
sig do | ||
params( | ||
version: T.nilable( | ||
T.any( | ||
String, | ||
Integer, | ||
Gem::Version | ||
) | ||
) | ||
) | ||
.void | ||
end | ||
def initialize(version); end | ||
end | ||
end |
This file contains 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