ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:96628] [Ruby master Bug#16473] New deprecated warning disallows arguments bypassing
       [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
@ 2020-01-02 17:10 ` aladjev.andrew
  2020-01-02 17:31 ` [ruby-core:96631] [Ruby master Bug#16473] New deprecated warning disallows keyword " merch-redmine
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: aladjev.andrew @ 2020-01-02 17:10 UTC (permalink / raw)
  To: ruby-core

Issue #16473 has been reported by puchuu (Andrew Aladjev).

----------------------------------------
Bug #16473: New deprecated warning disallows arguments bypassing
https://bugs.ruby-lang.org/issues/16473

* Author: puchuu (Andrew Aladjev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:96631] [Ruby master Bug#16473] New deprecated warning disallows keyword arguments bypassing
       [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
  2020-01-02 17:10 ` [ruby-core:96628] [Ruby master Bug#16473] New deprecated warning disallows arguments bypassing aladjev.andrew
@ 2020-01-02 17:31 ` merch-redmine
  2020-01-02 17:55 ` [ruby-core:96632] " aladjev.andrew
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2020-01-02 17:31 UTC (permalink / raw)
  To: ruby-core

Issue #16473 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Rejected

This behavior is expected.  The positional hash argument is converted to keyword arguments when `kw` is called.  That is not going to work in Ruby 3 (see #14183), hence the warning.

For delegating argument to a method that accepts keywords, you should probably use `ruby2_keywords` (if you also need to support older ruby versions):

```ruby
ruby2_keywords :non_kw if respond_to?(:ruby2_keywords, true)
```

----------------------------------------
Bug #16473: New deprecated warning disallows keyword arguments bypassing
https://bugs.ruby-lang.org/issues/16473#change-83601

* Author: puchuu (Andrew Aladjev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:96632] [Ruby master Bug#16473] New deprecated warning disallows keyword arguments bypassing
       [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
  2020-01-02 17:10 ` [ruby-core:96628] [Ruby master Bug#16473] New deprecated warning disallows arguments bypassing aladjev.andrew
  2020-01-02 17:31 ` [ruby-core:96631] [Ruby master Bug#16473] New deprecated warning disallows keyword " merch-redmine
@ 2020-01-02 17:55 ` aladjev.andrew
  2020-01-02 18:10 ` [ruby-core:96633] " merch-redmine
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: aladjev.andrew @ 2020-01-02 17:55 UTC (permalink / raw)
  To: ruby-core

Issue #16473 has been updated by puchuu (Andrew Aladjev).


@jeremyevans0, what will be the right way to bypass keyword arguments?

```ruby
def non_kw(a = {}, **keyword_args)
  puts "non kw #{a}"
  kw **keyword_args
end
```

This variant is wrong with ruby 2, because it provides:

```
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
```

Will it work with ruby 3? Thank you.

----------------------------------------
Bug #16473: New deprecated warning disallows keyword arguments bypassing
https://bugs.ruby-lang.org/issues/16473#change-83602

* Author: puchuu (Andrew Aladjev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:96633] [Ruby master Bug#16473] New deprecated warning disallows keyword arguments bypassing
       [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2020-01-02 17:55 ` [ruby-core:96632] " aladjev.andrew
@ 2020-01-02 18:10 ` merch-redmine
  2020-01-02 23:08 ` [ruby-core:96637] " daniel
  2020-01-02 23:29 ` [ruby-core:96638] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2020-01-02 18:10 UTC (permalink / raw)
  To: ruby-core

Issue #16473 has been updated by jeremyevans0 (Jeremy Evans).


puchuu (Andrew Aladjev) wrote:
> @jeremyevans0, what will be the right way to bypass keyword arguments?

As mentioned earlier, you should probably use `ruby2_keywords`. 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 `non_kw`.

----------------------------------------
Bug #16473: New deprecated warning disallows keyword arguments bypassing
https://bugs.ruby-lang.org/issues/16473#change-83603

* Author: puchuu (Andrew Aladjev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:96637] [Ruby master Bug#16473] New deprecated warning disallows keyword arguments bypassing
       [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2020-01-02 18:10 ` [ruby-core:96633] " merch-redmine
@ 2020-01-02 23:08 ` daniel
  2020-01-02 23:29 ` [ruby-core:96638] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: daniel @ 2020-01-02 23:08 UTC (permalink / raw)
  To: ruby-core

Issue #16473 has been updated by Dan0042 (Daniel DeLorme).


In this particular case there would be a bug if `*args` had more than one element, so I think the cleaner fix would be 

```ruby
def non_kw(a = {}, b = {})
  puts "non kw #{a}"
  kw **b
end
```

I really think the `ruby2_keywords` workaround should be strictly reserved for cases where portability and generic delegation _require_ it.

----------------------------------------
Bug #16473: New deprecated warning disallows keyword arguments bypassing
https://bugs.ruby-lang.org/issues/16473#change-83606

* Author: puchuu (Andrew Aladjev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:96638] [Ruby master Bug#16473] New deprecated warning disallows keyword arguments bypassing
       [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2020-01-02 23:08 ` [ruby-core:96637] " daniel
@ 2020-01-02 23:29 ` eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2020-01-02 23:29 UTC (permalink / raw)
  To: ruby-core

Issue #16473 has been updated by Eregon (Benoit Daloze).


This is one clear case where #16463 would solve it intuitively.

----------------------------------------
Bug #16473: New deprecated warning disallows keyword arguments bypassing
https://bugs.ruby-lang.org/issues/16473#change-83609

* Author: puchuu (Andrew Aladjev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.

```ruby
def kw(a: 1)
  puts "kw #{a}"
end

def non_kw(a = {}, *args)
  puts "non kw #{a}"
  kw *args
end

non_kw({ :a => 2 }, :a => 2)
non_kw({ :a => 3 })
non_kw
```

The right output is:

```
non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
```

Ruby 2.7.0 provides deprecated warning:
```ruby
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

`*args` is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-02 23:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16473.20200102171037@ruby-lang.org>
2020-01-02 17:10 ` [ruby-core:96628] [Ruby master Bug#16473] New deprecated warning disallows arguments bypassing aladjev.andrew
2020-01-02 17:31 ` [ruby-core:96631] [Ruby master Bug#16473] New deprecated warning disallows keyword " merch-redmine
2020-01-02 17:55 ` [ruby-core:96632] " aladjev.andrew
2020-01-02 18:10 ` [ruby-core:96633] " merch-redmine
2020-01-02 23:08 ` [ruby-core:96637] " daniel
2020-01-02 23:29 ` [ruby-core:96638] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).