Skip to content
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

ruby2.7 Using the last argument as keyword parameters is deprecated #2794

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ilkarataev
Copy link

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.

@jamis
Copy link
Contributor

jamis commented Oct 18, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants