-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Curl: Use typed: strict
#19077
base: master
Are you sure you want to change the base?
Curl: Use typed: strict
#19077
Conversation
d0610a9
to
4c40d4e
Compare
4c40d4e
to
176bb28
Compare
Thanks for this! I have a WIP branch for making all of |
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 @samford! Looking good so far.
77235c2
to
555981c
Compare
Changes in the latest push:
This passes
I looked back at some old Git stashes and apparently I've been intermittently working on this since at least 2022 (there were some challenges along the way, to say the least 😆). I finally finished it late last year and I had been meaning to create a PR but hadn't gotten around to it yet. I saw one of your Sorbet PRs the other day and thought, "Oh, I bet Issy's getting close to |
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.
Should be good once @dduugg's comment addressed!
44d25b6
to
a7bc571
Compare
This upgrades `utils/curl.rb` to `typed: strict`, which requires a number of changes to pass `brew typecheck`. The most straightforward are adding type signatures to methods, adding type annotations (e.g., `T.let`) to variables that need them, and ensuring that methods always use the expected return type. I had to refactor areas where we call a `Utils::Curl` method and use array destructuring on a `SystemCommand::Result` return value (e.g., `output, errors, status = curl_output(...)`), as Sorbet doesn't understand implicit array conversion. As suggested by Markus, I've switched these areas to use `#stdout`, `#stderr`, and `#status`. This requires the use of an intermediate variable (`result`) in some cases but this was a fairly straightforward substitution. I also had to refactor how `Cask::URL::BlockDSL::PageWithURL` works. It currently uses `page.extend PageWithURL` to add a `url` attribute but this reworks it to subclass `SimpleDelegator` and use an `initialize` method instead. This achieves the same goal but in a way that Sorbet can understand.
This adds more tests to `curl_spec.rb` to increase test coverage. This brings almost all of the methods that don't make network requests up to 100% line and branch coverage (the exception being some guards in `parse_curl_output` that shouldn't happen under normal circumstances). In the process of writing more tests for `parse_curl_response`, I made some tweaks to remove checks for conditions that shouldn't ever be true (e.g., `match["code"]` isn't optional, so it will be present if `HTTP_STATUS_LINE_REGEX` matches) and to refactor some others. I contributed this method a while back (9171eb2), so this is me coming back to clarify some behavior.
a7bc571
to
d812532
Compare
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?This upgrades
utils/curl.rb
totyped: strict
, which requires a number of changes to passbrew typecheck
. The most straightforward are adding type signatures to methods, adding type annotations (e.g.,T.let
) to variables that need them, and ensuring that methods always use the expected return type.I had to refactor areas where we call a
Utils::Curl
method and use array destructuring on aSystemCommand::Result
return value (e.g.,output, errors, status = curl_output(...)
), as Sorbet doesn't understand implicit array conversion. As suggested by Markus, I've switched these areas to use#stdout
,#stderr
, and#status
. This requires the use of an intermediate variable (result
) in some cases but this was a fairly straightforward substitution.I also had to refactor how
Cask::URL::BlockDSL::PageWithURL
works. Currently it usespage.extend PageWithURL
to add aurl
attribute but this reworks it to subclassString
SimpleDelegator
and use aninitialize
method instead. This achieves the same goal but in a way that Sorbet can understand.Besides that, this adds more tests to
curl_spec.rb
to increase test coverage. This brings almost all of the methods that don't make network requests up to 100% line and branch coverage (the exception being some guards inparse_curl_output
that shouldn't happen under normal circumstances). Overall coverage changes are as follows:brew tests
Command--only utils/curl
before--only utils/curl
after--online
before--online
afterIn the process of writing more tests for
parse_curl_response
, I made some tweaks to remove checks for conditions that shouldn't ever be true (e.g.,match["code"]
isn't optional, so it will be present ifHTTP_STATUS_LINE_REGEX
matches) and to refactor some others. I contributed this method a while back (9171eb2), so this is me coming back to clarify some behavior.Though this is worthwhile in its own right (#17297), this is a prelude to some potential
curl_args
changes to unblock a livecheck feature that I've been working on for some time.