ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:94422] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call
       [not found] <redmine.issue-16111.20190819054734@ruby-lang.org>
@ 2019-08-19  5:47 ` michael.telford
  2019-08-19  6:13 ` [ruby-core:94423] " mame
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: michael.telford @ 2019-08-19  5:47 UTC (permalink / raw)
  To: ruby-core

Issue #16111 has been reported by mtelford (Michael Telford).

----------------------------------------
Bug #16111: Combining default positional and keyword arguments is resulting in a `to_hash` method call
https://bugs.ruby-lang.org/issues/16111

* Author: mtelford (Michael Telford)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Combining default positional and keyword arguments is resulting in a `to_hash` method call when I don't believe it should be. It's affecting some code I am writing. The full details of the behaviour I'm describing can be seen in the attached script.

I would like to know why the method `to_hash` is being called (only in certain circumstances) and if this is a bug to be fixed or desired behaviour (and why?).

Thank in advance!

---Files--------------------------------
ruby-bug.rb (1.44 KB)


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

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

* [ruby-core:94423] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call
       [not found] <redmine.issue-16111.20190819054734@ruby-lang.org>
  2019-08-19  5:47 ` [ruby-core:94422] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call michael.telford
@ 2019-08-19  6:13 ` mame
  2019-08-19  8:22 ` [ruby-core:94429] " michael.telford
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: mame @ 2019-08-19  6:13 UTC (permalink / raw)
  To: ruby-core

Issue #16111 has been updated by mame (Yusuke Endoh).


> I would like to know why the method to_hash is being called

A method call that accepts keywords checks if the last argument is a Hash or not.  The check includes attempting to convert it by using `to_hash`.  This is the behavior you are seeing.

I agree that it is very strange.  It is elegantly solved if we can separate positional and keyword arguments completely (#14183), but the separation seems to be difficult because the incompatibility is painful.

----------------------------------------
Bug #16111: Combining default positional and keyword arguments is resulting in a `to_hash` method call
https://bugs.ruby-lang.org/issues/16111#change-80848

* Author: mtelford (Michael Telford)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Combining default positional and keyword arguments is resulting in a `to_hash` method call when I don't believe it should be. It's affecting some code I am writing. The full details of the behaviour I'm describing can be seen in the attached script.

I would like to know why the method `to_hash` is being called (only in certain circumstances) and if this is a bug to be fixed or desired behaviour (and why?).

Thank in advance!

---Files--------------------------------
ruby-bug.rb (1.44 KB)


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

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

* [ruby-core:94429] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call
       [not found] <redmine.issue-16111.20190819054734@ruby-lang.org>
  2019-08-19  5:47 ` [ruby-core:94422] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call michael.telford
  2019-08-19  6:13 ` [ruby-core:94423] " mame
@ 2019-08-19  8:22 ` michael.telford
  2019-08-19 16:45 ` [ruby-core:94437] " shevegen
  2019-08-20 14:26 ` [ruby-core:94446] " michael.telford
  4 siblings, 0 replies; 5+ messages in thread
From: michael.telford @ 2019-08-19  8:22 UTC (permalink / raw)
  To: ruby-core

Issue #16111 has been updated by mtelford (Michael Telford).


Ok, thanks for the reply. That now makes more sense. I understand why the last positional argument is type-checked but surely trying to convert it using `param#to_hash` is a step too far? Doing so basically means that the last positional argument cannot `respond_to? :to_hash`, as in my case. It's not ideal as my problem still exists. 

----------------------------------------
Bug #16111: Combining default positional and keyword arguments is resulting in a `to_hash` method call
https://bugs.ruby-lang.org/issues/16111#change-80853

* Author: mtelford (Michael Telford)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Combining default positional and keyword arguments is resulting in a `to_hash` method call when I don't believe it should be. It's affecting some code I am writing. The full details of the behaviour I'm describing can be seen in the attached script.

I would like to know why the method `to_hash` is being called (only in certain circumstances) and if this is a bug to be fixed or desired behaviour (and why?).

Thank in advance!

---Files--------------------------------
ruby-bug.rb (1.44 KB)


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

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

* [ruby-core:94437] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call
       [not found] <redmine.issue-16111.20190819054734@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-19  8:22 ` [ruby-core:94429] " michael.telford
@ 2019-08-19 16:45 ` shevegen
  2019-08-20 14:26 ` [ruby-core:94446] " michael.telford
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2019-08-19 16:45 UTC (permalink / raw)
  To: ruby-core

Issue #16111 has been updated by shevegen (Robert A. Heiler).


I think that either way, resolving it may not be trivial/simple right now; if you
look at mame's linked in issue above at #14183, it mentions 19 (somewhat) related
issues concerning keyword arguments. Jeremy also pointed out some bugs prior to
this, and if I remember correctly, matz spoke about the somewhat confusing situation
in a presentation a while ago. This may need to be given some time, for the time
being, but the ruby core team is most likely aware of the situation.

I personally have avoided keyword arguments so far (but unrelated to the issues
mentioned in the issue trackers; I mostly stick to oldschool hashes. Perhaps
this may also be somewhat of a "historic" nature, in that hash-behaviour 
came first (the old pickaxe mentioned that, e. g. you could drop the {}
syntax for the last arguments in a method if it was a hash), and at a later
time keyword arguments were added.

If I remember correctly then matz has also mention that the situation with
keyword arguments may be one of the very very few incompatibilities for
ruby 3.0 (perhaps), so I guess it is not out of the question to see a 
change in behaviour in this regard. As mame has pointed out, one of the
biggest concern, if not the biggest, is the incompatibility issue.

----------------------------------------
Bug #16111: Combining default positional and keyword arguments is resulting in a `to_hash` method call
https://bugs.ruby-lang.org/issues/16111#change-80862

* Author: mtelford (Michael Telford)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Combining default positional and keyword arguments is resulting in a `to_hash` method call when I don't believe it should be. It's affecting some code I am writing. The full details of the behaviour I'm describing can be seen in the attached script.

I would like to know why the method `to_hash` is being called (only in certain circumstances) and if this is a bug to be fixed or desired behaviour (and why?).

Thank in advance!

---Files--------------------------------
ruby-bug.rb (1.44 KB)


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

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

* [ruby-core:94446] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call
       [not found] <redmine.issue-16111.20190819054734@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-08-19 16:45 ` [ruby-core:94437] " shevegen
@ 2019-08-20 14:26 ` michael.telford
  4 siblings, 0 replies; 5+ messages in thread
From: michael.telford @ 2019-08-20 14:26 UTC (permalink / raw)
  To: ruby-core

Issue #16111 has been updated by mtelford (Michael Telford).


Ok, the situation with keyword parameters is now making more sense, despite not being ideal. Since ruby 3 should implement a fix (backwards compatible or not) I am happy for this issue to be closed. 

Thanks to those who commented to bring me up to speed :-)

----------------------------------------
Bug #16111: Combining default positional and keyword arguments is resulting in a `to_hash` method call
https://bugs.ruby-lang.org/issues/16111#change-80872

* Author: mtelford (Michael Telford)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Combining default positional and keyword arguments is resulting in a `to_hash` method call when I don't believe it should be. It's affecting some code I am writing. The full details of the behaviour I'm describing can be seen in the attached script.

I would like to know why the method `to_hash` is being called (only in certain circumstances) and if this is a bug to be fixed or desired behaviour (and why?).

Thank in advance!

---Files--------------------------------
ruby-bug.rb (1.44 KB)


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

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

end of thread, other threads:[~2019-08-20 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16111.20190819054734@ruby-lang.org>
2019-08-19  5:47 ` [ruby-core:94422] [Ruby master Bug#16111] Combining default positional and keyword arguments is resulting in a `to_hash` method call michael.telford
2019-08-19  6:13 ` [ruby-core:94423] " mame
2019-08-19  8:22 ` [ruby-core:94429] " michael.telford
2019-08-19 16:45 ` [ruby-core:94437] " shevegen
2019-08-20 14:26 ` [ruby-core:94446] " michael.telford

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).