-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add more signatures for #present?
for Rails 7.2
#265
Add more signatures for #present?
for Rails 7.2
#265
Conversation
Ah, I guess the reason why we really need this is because Tapioca will now generate versions of The motivation for adding these wasn't very clear to me until I understood this, so wanted to share for other onlookers. |
I think we should also add: class NilClass
sig { returns(TrueClass) }
def blank?; end
sig { returns(FalseClass) }
def present?; end
end
class FalseClass
sig { returns(TrueClass) }
def blank?; end
sig { returns(FalseClass) }
def present?; end
end
class TrueClass
sig { returns(FalseClass) }
def blank?; end
sig { returns(TrueClass) }
def present?; end
end
class Numeric
sig { returns(FalseClass) }
def blank?; end
sig { returns(TrueClass) }
def present?; end
end
class Time
sig { returns(FalseClass) }
def blank?; end
sig { returns(TrueClass) }
def present?; end
end |
@paracycle Those all already exist :) Though some are marked as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Looks like it needs a rebase
824ab93
to
1a1e940
Compare
@@ -75,11 +75,23 @@ class Object | |||
end | |||
|
|||
class Hash | |||
sig { returns(T::Boolean)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind submitting a quick patch to fix the spacing? (We should add RuboCop to this repo hah)
sig { returns(T::Boolean)} | |
sig { returns(T::Boolean) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do run rubocop, I'll add a test for this and see what's happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type of Change
Changes
Rails 7.2 defines
#present?
methods directly on a few classes likeArray
,Hash
,Numeric
etc.This requires new signatures, otherwise Sorbet defaults to
T.untyped
: https://sorbet.run/#%23%20typed%3A%20true%0A%0Aclass%20Object%0A%20%20extend%20T%3A%3ASig%0A%0A%20%20sig%20%7B%20returns%28T%3A%3ABoolean%29%20%7D%0A%20%20def%20blank%3F%0A%20%20%20%20respond_to%3F%28%3Aempty%3F%29%20%3F%20!!%28T.unsafe%28self%29.empty%3F%29%20%3A%20false%0A%20%20end%0A%0A%20%20sig%20%7B%20returns%28T%3A%3ABoolean%29%20%7D%0A%20%20def%20present%3F%0A%20%20%20%20!blank%3F%0A%20%20end%0Aend%0A%0Aclass%20Array%0A%20%20alias_method%20%3Ablank%3F%2C%20%3Aempty%3F%0Aend%0A%0Aclass%20ArrayRails72%20%3C%20Array%0A%20%20%23%20sig%20%7B%20returns%28T%3A%3ABoolean%29%20%7D%0A%20%20def%20present%3F%0A%20%20%20%20!empty%3F%0A%20%20end%0Aend%0A%0Aarr%20%3D%20%5B%5D%0AT.reveal_type%28arr.present%3F%29%0A%0Aarr_72%20%3D%20ArrayRails72.new%0AT.reveal_type%28arr_72.present%3F%29%0AThis should be safe to merge and use with previous Rails versions though, since the
#present?
method does exist onArray
andHash
even with Rails 7.1, it's just inherited fromObject
rather than defined directly on the classes.