-
Couldn't load subscription status.
- Fork 533
ruby2.7 Using the last argument as keyword parameters is deprecated #2794
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
Conversation
Thanks for pointing this out! It looks like this is actually a problem with Ruby 2.7 and its parser; the same warning does not appear in Ruby 3.x. The call as given should be fine, because the empty hash is supposed to map to the config parameter, which is not a keyword argument. Ruby 2.7 is apparently trying to connect the empty hash to the subsequent keyword arguments, though.
Ultimately, the empty hash is redundant because the Description initializer has default values for all of those. Rather than tag the hash as keyword arguments, I think it might be better to just remove it from that call altogether:
Mongo::Server::Description.new(address)
If we do want to preserve the empty hash as a hint that we're truly producing an empty server description, something like the following would be more accurate:
Mongo::Server::Description.new(address, {}, **{})
/cc @comandeo -- do you have any opinions here?
comandeo
commented
Oct 20, 2023
I second what @jamis wrote above. I believe we should use just Mongo::Server::Description.new(address) here; it should be clear enough from the context that we create an empty description.
...delete second parametr
Hi I faced problem on my script I saw warnings:
/var/lib/gems/2.7.0/gems/mongo-2.19.1/lib/mongo/server.rb:658: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/mongo-2.19.1/lib/mongo/server/description.rb:220: warning: The called method `initialize' is defined here
This small changes fix the problem.