From: "jeremyevans0 (Jeremy Evans) via ruby-core" Date: 2024-05-30T06:09:42+00:00 Subject: [ruby-core:118091] [Ruby master Bug#20513] the feature of kwargs in index methods has been removed without due consideration of utility and compatibility Issue #20513 has been updated by jeremyevans0 (Jeremy Evans). In my opinion, opening a new issue just because you didn't get the response you wanted to your comments in the original issue (#20218) is not an appropriate way to handle things. If you would like @matz to reconsider his decision, add issue #20218 as a discussion item for the next developer meeting (#20435). The support for keyword arguments in aset/op_asgn/masgn was not removed just because multiple assignment was broken. That could have been fixed, as I fixed operator assignment in Ruby 3.3. I fixed operator assignment in Ruby 3.3 because it was segfaulting, without realizing the resulting keyword argument behavior differed from aset and without realizing mass assignment had the same issue. I agree that a decision to remove syntax should not be made lightly, and I don't think it was. However, fixing the `a[1, kw: 2] = 3` syntax to correctly support keyword arguments would result in silent behavior changes, which is much worse than raising a SyntaxError. Maybe you believe that silent behavior changes are better than raising a SyntaxError, but I doubt that is a commonly held belief. Even if you fixed aset to treat keywords correctly, the behavior is strange, because the rhs would be inserted between the positional arguments and keyword arguments. While technically correct in regards to keyword argument separation, I think inserting the rhs between the positional and keyword arguments of the lhs is a bad idea from a language design perspective. I see three possibilities: 1. Treat keyword arguments as positional in aset/op_asgn/masgn. This is inconsistent with keyword argument separation, and silently breaks op_asgn backwards compatibility with Ruby 3.3. 2. Treat keyword arguments as keywords in aset/op_asgn/masgn. This results in poor language design, and silently breaks aset backwards compatibility with most previous Ruby versions. 3. Remove the syntax, which avoids the problems with options 1 and 2. Still backwards incompatible, but not silently backwards incompatible. I can easily see why @matz chose option 3 in this case. ---------------------------------------- Bug #20513: the feature of kwargs in index methods has been removed without due consideration of utility and compatibility https://bugs.ruby-lang.org/issues/20513#change-108519 * Author: bughit (bug hit) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- See #20218 The ability to pass kwargs to index methods has been in ruby for a long time, probably from the inception of kwargs, so there's code that makes use of it. Other than the multiple assignment edge-case it's been working fine and is not conceptually unsound. kwargs allow for more variability in store/lookup operations via index methods, letting you control where/how something is stored/looked up. this is from 2.6 ```ruby module IndexTest @store = {} def self.store @store end def self.key(name, namespace: nil) name = "#{namespace}:#{name}" if namespace name end def self.[](name, namespace: nil) p [name, namespace] @store[key(name, namespace: namespace)] end def self.[]=(name, opts = {}, val) p [name, opts, val] @store[key(name, namespace: opts[:namespace])] = val end end IndexTest['foo'] = 1 p IndexTest['foo'] IndexTest['foo', namespace: 'bar'] = 2 p IndexTest['foo', namespace: 'bar'] p IndexTest.store ``` A reasonable breaking change would be for `[]=` to have real kwargs, rather than the middle positional kwarg collector hash in the above example. I am not arguing that breaking changes can't be introduced, but that a removal of a long-standing feature deserves more consideration and deliberation than the following: > I found that use of keyword arguments in multiple assignment is broken > Can we also prohibit keyword arguments ... ? > OK, prohibit keyword arguments -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/