-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
[bugfix] Properly detect kwargs hashes vs optional positional args #594
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
0645cdf
to
2b4d422
Compare
2b4d422
to
ef33ab7
Compare
d61bf73
to
c0ea86c
Compare
990054f
to
6eb38eb
Compare
75432d1
to
fd1dbb6
Compare
Fully backwards compatible, just need to fix 3.2 and up. The behavior of ruby2_keywords changed between 3.1 and 3.2: https://rubyreferences.github.io/rubychanges/3.2.html#keyword-argument-separation-leftovers |
def initialize(signature, args=[]) | ||
@signature = signature | ||
@non_kw_args, @kw_args = split_args(*args) | ||
@non_kw_args, @kw_args = split_args(args.clone) | ||
@min_non_kw_args = @max_non_kw_args = @non_kw_args | ||
@arbitrary_kw_args = @unlimited_args = false | ||
end |
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.
something had to change here. Splatting the args meant the special marking for the kwargs hash gets lost. This doesnt happen to functions with the ruby2_keywords... except it won't apply here because this function doesn't take the *args input. So either the args array is cloned (which persists the special flagging) or the input to this function needs to swap to using *args. I figured cloning was the less obtrusive change. The split_args function is private so changing its signature was not something that has compatibility concerns.
Attempting to fix rspec/rspec-expectations#1451
Refactor
has_kw_args_in?
:Added backwards compatible ruby2_keywords wrapping to the necessary methods (valid? and error_for) in the spec files like so:
ruby2_keywords(:valid?) if respond_to?(:ruby2_keywords, true)
Also needed to modify how args are passed to the MSV split_args so that the special kwargs markings are not lost.