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
Refactor CaskLoader::for
.
#16609
Refactor CaskLoader::for
.
#16609
Conversation
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.
I left a bunch of nits but of course you can ignore those. Other than the use of Tap#ensure_installed!
that I'm a bit worried about this looks very good and helps clean up a lot of the code.
class FromContentLoader < AbstractContentLoader | ||
def self.can_load?(ref) | ||
def self.try_new(ref, warn: false) |
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.
I like this approach but I am 50/50 on the name. I don't have any better ideas though.
Would this approach make it easier to streamline formula loading as well? The current #can_load?
style logic doesn't really work well for formulae since we need a bunch of workarounds and extra checks when deciding what to load.
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.
Yes, I hope we can use the same pattern for formulae as well.
@content = content.force_encoding("UTF-8") | ||
@content = content.dup.force_encoding("UTF-8") |
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.
I doubt the String#dup
is really necessary here. Are we relying on the original string encoding anywhere else?
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.
Some tests were failing here because they pass in string literals. It is surprising that this is necessary only now though.
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.
Oh right, we were only testing can_load?
before, not the constructor.
return false unless ref.respond_to?(:to_str) | ||
|
||
content = ref.to_str | ||
content = T.unsafe(ref).to_str |
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.
I'm a bit surprised that Sorbet can't figure this one out. sigh
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.
Yes, unfortunate, but it does make sense: https://sorbet.org/docs/flow-sensitive#what-about-respond_to
You cannot deduce a type by its methods alone. We could just use is_a?(String)
here though, because anything else doesn't make sense anyways.
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.
Either way is fine for me. Thanks for explaining it to me.
Co-authored-by: Kevin <apainintheneck@gmail.com>
Co-authored-by: Kevin <apainintheneck@gmail.com>
659932e
to
c301b9c
Compare
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.
Looks good to me now, thanks!
return false unless ref.respond_to?(:to_str) | ||
|
||
content = ref.to_str | ||
content = T.unsafe(ref).to_str |
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.
Either way is fine for me. Thanks for explaining it to me.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Revert #16608 and refactor
CaskLoader::for
to use the same logic for full and short names, which hopefully also fixes #16607 properly.