https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112020-01-02T17:10:59ZRuby Issue Tracking SystemRuby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=835982020-01-02T17:10:59Zpuchuu (Andrew Aladjev)aladjev.andrew@gmail.com
<ul><li><strong>Subject</strong> changed from <i>New deprecated warning disallows arguments bypassing</i> to <i>New deprecated warning disallows keyword arguments bypassing</i></li></ul> Ruby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=836012020-01-02T17:31:14Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>This behavior is expected. The positional hash argument is converted to keyword arguments when <code>kw</code> is called. That is not going to work in Ruby 3 (see <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: "Real" keyword argument (Closed)" href="https://redmine.ruby-lang.org/issues/14183">#14183</a>), hence the warning.</p>
<p>For delegating argument to a method that accepts keywords, you should probably use <code>ruby2_keywords</code> (if you also need to support older ruby versions):</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">ruby2_keywords</span> <span class="ss">:non_kw</span> <span class="k">if</span> <span class="nb">respond_to?</span><span class="p">(</span><span class="ss">:ruby2_keywords</span><span class="p">,</span> <span class="kp">true</span><span class="p">)</span>
</code></pre> Ruby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=836022020-01-02T17:55:05Zpuchuu (Andrew Aladjev)aladjev.andrew@gmail.com
<ul></ul><p><a class="user active user-mention" href="https://redmine.ruby-lang.org/users/1604">@jeremyevans0 (Jeremy Evans)</a>, what will be the right way to bypass keyword arguments?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">non_kw</span><span class="p">(</span><span class="n">a</span> <span class="o">=</span> <span class="p">{},</span> <span class="o">**</span><span class="n">keyword_args</span><span class="p">)</span>
<span class="nb">puts</span> <span class="s2">"non kw </span><span class="si">#{</span><span class="n">a</span><span class="si">}</span><span class="s2">"</span>
<span class="n">kw</span> <span class="o">**</span><span class="n">keyword_args</span>
<span class="k">end</span>
</code></pre>
<p>This variant is wrong with ruby 2, because it provides:</p>
<pre><code>non kw {:a=>2}
kw 2
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
warning: The called method `non_kw' is defined here
non kw {}
kw 3
non kw {}
kw 1
</code></pre>
<p>Will it work with ruby 3? Thank you.</p> Ruby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=836032020-01-02T18:10:01Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>puchuu (Andrew Aladjev) wrote:</p>
<blockquote>
<p><a class="user active user-mention" href="https://redmine.ruby-lang.org/users/1604">@jeremyevans0 (Jeremy Evans)</a>, what will be the right way to bypass keyword arguments?</p>
</blockquote>
<p>As mentioned earlier, you should probably use <code>ruby2_keywords</code>. In this particular case, even if you don't want to support earlier Ruby versions, because you don't want the positional hash argument being interpreted as keywords by <code>non_kw</code>.</p> Ruby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=836062020-01-02T23:08:31ZDan0042 (Daniel DeLorme)
<ul></ul><p>In this particular case there would be a bug if <code>*args</code> had more than one element, so I think the cleaner fix would be</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">non_kw</span><span class="p">(</span><span class="n">a</span> <span class="o">=</span> <span class="p">{},</span> <span class="n">b</span> <span class="o">=</span> <span class="p">{})</span>
<span class="nb">puts</span> <span class="s2">"non kw </span><span class="si">#{</span><span class="n">a</span><span class="si">}</span><span class="s2">"</span>
<span class="n">kw</span> <span class="o">**</span><span class="n">b</span>
<span class="k">end</span>
</code></pre>
<p>I really think the <code>ruby2_keywords</code> workaround should be strictly reserved for cases where portability and generic delegation <em>require</em> it.</p> Ruby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=836082020-01-02T23:28:56ZEregon (Benoit Daloze)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/16463">Feature #16463</a>: Fixing *args-delegation in Ruby 2.7: ruby2_keywords semantics by default in 2.7.1</i> added</li></ul> Ruby master - Bug #16473: New deprecated warning disallows keyword arguments bypassinghttps://redmine.ruby-lang.org/issues/16473?journal_id=836092020-01-02T23:29:20ZEregon (Benoit Daloze)
<ul></ul><p>This is one clear case where <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Fixing *args-delegation in Ruby 2.7: ruby2_keywords semantics by default in 2.7.1 (Closed)" href="https://redmine.ruby-lang.org/issues/16463">#16463</a> would solve it intuitively.</p>