-
-
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
livecheck: replace T.unsafe with T.nilable #16933
Conversation
Signed-off-by: Michael Cho <michael@michaelcho.dev>
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.
The point of having non-nilable arguments is to prevent explicitly passing nil
as an argument, when in fact we want either a non-nilable argument or no argument at all.
Making the arguments nilable (rather than simply optional as is the case with T.unsafe
) makes type-checking less meaningful.
I guess for |
This seems better. |
I don't think it's worth making the type checking less strict just to clean up some ugly syntax. |
Using However, where I think we do agree is that having a method that looks like this smells a lot of "let's add types to an existing method rather than refactoring the method" (which is exactly what happened and why the types in this file are not very nicely handled). |
It's more strict for the arguments that get passed in but less strict from that point on for the default argument. I think any other String arguments will be evaluated normally though. Not entirely sure though.
To be fair we can't really refactor these methods because they're public API at this point. It looks like there are three other examples of this pattern in the code. I don't think the one in the source location file is needed at a glance.
I'm fine with getting rid of it if we don't want to be as strict. As currently written it should cause errors when nil is passed as an argument to these methods. I don't think we should use the empty string and -1 argument hacks though. That's the worst option of the three. It'd be nice to update the other ones too to keep it consistent. Also, this pattern is used a lot in |
Agreed with all of this 👍🏻 |
Based on comments so far, there isn't a consensus on how to best handle. I see at least one disagreement with each approach. I may just close this for now and revisit when we've gotten closer to fully typing all of Perhaps along the boundary of a release where we can introduce some API changes (i.e. non-breaking for loading formulae/casks but potentially breaking for external usage of |
I think that's reasonable, sorry for the wasted effort here ❤️. I suspect eventually we'll want to move to Sorbet "strict" mode and that may define how we do this. |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Follow up of thread at #16918 (comment)