-
Notifications
You must be signed in to change notification settings - Fork 136
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
Rename #sorbet_type
→ #__tapioca_type
#2125
Conversation
37a0896
to
0f37d00
Compare
@@ -147,7 +147,17 @@ def type_for(property) | |||
return "T.untyped" if type.nil? | |||
|
|||
sorbet_type = if type.respond_to?(:sorbet_type) | |||
line, file = type.method(:sorbet_type).source_location |
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.
This assumes that the source_location
is available (i.e. this was defined in Ruby, and not in a C extension). Is that safe to assume, or should I guard against it?
Doing so is a bit uglier:
msg = <<~MESSAGE
WARNING: `#sorbet_type` is deprecated. Please rename your method to `#__tapioca_type`."
MESSAGE
if (source_location = type.method(:sorbet_type).source_location)
msg.concat("Defined on line #{source_location[0]} of #{source_location[1]}")
end
msg = $stderr.puts
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.
Could also be nil
if there's some metaprogramming involved, so let's play it safe. You could extract out the deprecation stuff so as to not pollute the conditional.
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.
Fixed!
0f37d00
to
9298261
Compare
end | ||
RUBY | ||
|
||
rbi_for(:Post) # Should not raise |
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 don't have assert_nothing_raised
, so a comment will suffice.
def self.method(name) | ||
m = super | ||
# Fake the source location, as if this was defined in a C extension. | ||
def m.source_location |
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.
It's surprisingly hard to make a method with no source_location
ahha. Native methods from C extensions would have it, but other than that, every way to define a Ruby method ended up having it defined. I tried:
define_singleton_method
singleton_class.define_method
eval
class_eval
Class.new { ... }
and they all had it defined.
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.
Interesting.
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.
IKR? I could have sworn you needed to explicitly pass in the ___FILE__
and __LINE__
else you got no info at all
Motivation
Rename the
#sorbet_type
method called by theJsonApiClient::Resource
compiler, to match our naming decision in #2112:__
to discourage the method from being called from regular user code (i.e. only Tapioca should be calling it).Implementation
Print a warning when we find
#sorbet_type
, while still honouring it. If there's only a definition for#__tapioca_type
, we'll use that instead.After some migration time, we can drop support for
#sorbet_type
.