mongo-ruby-driver icon indicating copy to clipboard operation
mongo-ruby-driver copied to clipboard

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

Open ilkarataev opened this issue 2 years ago • 2 comments
trafficstars

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.

ilkarataev avatar Oct 17 '23 09:10 ilkarataev

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?

jamis avatar Oct 18 '23 14:10 jamis

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.

comandeo avatar Oct 20 '23 15:10 comandeo