-
Notifications
You must be signed in to change notification settings - Fork 63
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
Test against Ruby 3.2, fix broken things #134
Conversation
@jkowens are you able to add more maintainers here on GitHub? Would be good to have more people being able to approve CI runs Anyway, I ran the tests in my fork, see https://github.com/dentarg/mustermann/actions/runs/2702649077, looks like this needs more work |
Also, @eregon probably knows how to handle this :) |
Thanks, looks like edit: or not, I took that from the README for the edit2: or not not, moving the |
@@ -91,6 +93,10 @@ def type | |||
self.class.type | |||
end | |||
|
|||
class << self | |||
ruby2_keywords :parse | |||
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.
Could you move it just below the declaration of def self.parse
? Otherwise it's hard to find (in both directions).
Yes, slightly more |
I've also found there is a way to run actions without needing approvals except for new users on GitHub in the repo's Actions settings, that seems convenient. |
The build now passes on my fork on 3.2: https://github.com/magni-/mustermann/runs/7430295996?check_suite_focus=true#step:5:15 It turned out the main cause of failures was the removal of While grepping for other places that might be missing a diff --git mustermann-contrib/lib/mustermann/flask.rb mustermann-contrib/lib/mustermann/flask.rb
index 4caa3b8..848deab 100644
--- mustermann-contrib/lib/mustermann/flask.rb
+++ mustermann-contrib/lib/mustermann/flask.rb
@@ -179,11 +179,11 @@ def self.register_converter(name, converter = nil, &block)
converter.node_type = :named_splat
end
- register_converter(:any) do |converter, *strings|
+ register_converter(:any, &-> (converter, *strings) do
strings = strings.map { |s| Regexp.escape(s) unless s == {} }.compact
converter.qualifier = ""
converter.constraint = Regexp.union(*strings)
- end
+ end.ruby2_keywords)
register_converter(:default, converters['string'])
diff --git mustermann/lib/mustermann/ast/transformer.rb mustermann/lib/mustermann/ast/transformer.rb
index f21f8f3..bdfe93f 100644
--- mustermann/lib/mustermann/ast/transformer.rb
+++ mustermann/lib/mustermann/ast/transformer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+require 'ruby2_keywords'
require 'mustermann/ast/translator'
module Mustermann
@@ -139,7 +140,7 @@ def track(element)
# turn look ahead buffer into look ahead node
# @!visibility private
- def create_lookahead(elements, *args)
+ ruby2_keywords def create_lookahead(elements, *args)
return elements unless elements.size > 1
[Node[:with_look_ahead].new(elements, *args, start: elements.first.start, stop: elements.last.stop)]
end But the build passes without these changes and I'm really unfamiliar with both this codebase and the |
An alternative would be to mark the method with `ruby2_keywords`: From the Ruby 3.2 changelog: > Methods taking a rest parameter (like `*args`) and wishing to delegate keyword arguments through `foo(*args)` must now be marked with `ruby2_keywords` (if not already the case). In other words, all methods wishing to delegate keyword arguments through `*args` must now be marked with `ruby2_keywords`, with no exception. This will make it easier to transition to other ways of delegation once a library can require Ruby 3+. Previously, the `ruby2_keywords` flag was kept if the receiving method took `*args`, but this was a bug and an inconsistency. A good technique to find the potentially-missing `ruby2_keywords` is to run the test suite, for where it fails find the last method which must receive keyword arguments, use `puts nil, caller, nil` there, and check each method/block on the call chain which must delegate keywords is correctly marked as `ruby2_keywords`. [[Bug #18625](https://bugs.ruby-lang.org/issues/18625)] [[Bug #16466](https://bugs.ruby-lang.org/issues/16466)] `Node.parse` takes `*args` and delegates them to `Node.new`, therefore it needs to be marked with `ruby2_keywords`.
`Kernel` defined `#=~` up until Ruby 3.2, but it just returned `nil` when the method wasn't redefined by a child class.
@dentarg I wish I could, but I don't have access to do that. @zzak could you help us out with that? |
Also, while the specs pass, the coverage checks blows up because of the removal of the deprecated
|
Looks like is passing as expected. Good to merge? What release version should this go out as? Is releasing this in 3.0 ok, or do we need a patch release in the 2x series? |
I'd welcome @eregon's eyes on this again since I gather he knows far more about these Ruby 3.2 changes than I do 🙇🏼
Since 3.0 isn't out yet, might as well release it on 2.x first? Looking at #133, there should be just the small conflict in |
Looks like it is the sending to Coveralls that doesn't work but that's already the case for the other jobs too ( |
@@ -124,6 +124,8 @@ def error_for(values) | |||
# @see Mustermann::AST::Translator#expand | |||
# @!visibility private | |||
ruby2_keywords def escape(string, *args) | |||
return super unless string.respond_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.
If it's just nil/false, I'd simplify to return super unless string
or integrate it in the ternary below.
Or are other types seen?
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.
From the build failures, it's Integer
s: https://github.com/magni-/mustermann/runs/7425121555?check_suite_focus=true#step:5:14
e.g.
9) Mustermann::Expander supports combining different pattern styles
Failure/Error: expander.expand(bar: 23).should be == "/23"
NoMethodError:
undefined method `=~' for 23:Integer
# ./mustermann/lib/mustermann/ast/expander.rb:128:in `escape'
# ./mustermann/lib/mustermann/ast/expander.rb:99:in `block in expand'
# ./mustermann/lib/mustermann/ast/expander.rb:99:in `each'
# ./mustermann/lib/mustermann/ast/expander.rb:99:in `expand'
# ./mustermann/lib/mustermann/expander.rb:150:in `expand'
# ./mustermann/spec/expander_spec.rb:26:in `block (2 levels) in <top (required)>'
@magni- The first change looks wrong to me, because strings = strings.map { |s| Regexp.escape(s) unless s == {} }.compact What passes a empty hash to that method? That seems wrong. I think such callers should be fixed to not pass any kwargs or hashes. The second change also looks strange to me, because AFAIK one cannot use a [Node[:with_look_ahead].new(elements, *args, start: elements.first.start, stop: elements.last.stop)] An example which show it does not work:
Do you actually have more warnings or errors without these 2 |
Ah I missed the end of your message:
From what I can see they are not needed and not correct (well, simply not needed/no effect and might cause warnings). |
def self.parse(payload = nil, **options, &block) | ||
new(payload, **options).tap { |n| n.parse(&block) } |
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 👍
ruby2_keywords
Anything else needed for this PR? 🙇🏼 |
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.
IMHO good to merge
My build for a PR in
ruby-grape/grape-swagger
, which depends onmustermann
, failed on Ruby 3.2. Digging into the failure, it seems to be caused by a change concerningruby2_keywords
:There's probably other methods that now need to be marked? I added
head
to the CI test matrix, so those should be caught there.