ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: mame@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96835] [Ruby master Bug#16486] Hash.ruby2_keywords?(hash) and Hash.ruby2_keywords!(hash)
Date: Tue, 14 Jan 2020 06:27:16 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-83838.20200114062715.658ed762de9c7a22@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16486.20200106094637@ruby-lang.org

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


Hi, I talked about this ticket with ko1, nobu, and znz before the dev-meeting.  After the discussion, I am still against this.

We premise that the ruby2_keywords flag is never a wonderful thing.  We want to delete it in the future.  `Module#ruby2_keywords` will serve as a mark showing "we need to change this method definition so to accept not only positional rest arguments but also keyword ones explicitly if ruby2_keywords flag is deleted."

So, assuming the flag is removed at Ruby 4.0, we'd like users to change their code in the following style:

```
# 2.6
def foo(*args)
  bar(*args)
end
```

```
# 2.7 .. 4.0 (until ruby2_keywords flag is deprecated)
ruby2_keywords def foo(*args)
  bar(*args)
end
```

```
# 4.0 ..
def foo(*args, **kwargs)
  bar(*args, **kwargs)
end

# or, if possible
def foo(...)
  bar(...)
end
```

If we set `ruby2_keywords` by default, users cannot identify where to fix, and their code will break suddenly after the flag is removed.  It would be unacceptable and we will be unable to deprecate `Module#ruby2_keywords` forever.  This is not what we want.

----------------------------------------
Bug #16486: Hash.ruby2_keywords?(hash) and Hash.ruby2_keywords!(hash)
https://bugs.ruby-lang.org/issues/16486#change-83838

* Author: mame (Yusuke Endoh)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
* ruby -v: 
* Backport: 2.5: DONTNEED, 2.6: DONTNEED, 2.7: REQUIRED
----------------------------------------
Hash's ruby2_keywords flag is designed to be as implicit as possible, but unfortunately, sometimes we need to handle the flag explicitly.  In ActiveJob, the whole arguments are serialized and deserialized, and the process removes the flag; in this case, we need to check and save the flag when serializing, and restore the flag when deserializing.

https://github.com/rails/rails/pull/38105#discussion_r361863767

It is theoretically possible by [a very hacky code](https://gist.github.com/mame/18cd2dfc7d965d0bad1216f2fdd008ee#file-bouncing_test-patch-L117-L134), but it would be good to provide them officially.

https://github.com/ruby/ruby/pull/2818

* `Hash.ruby2_keywords?(hash)` checks if hash is flagged or not.
* `Hash.ruby2_keywords!(hash)` flags a given hash.

The reason why I don't add them as instance methods (`Hash#ruby2_keywords?`) is that they are never for casual use.  The ruby2_keywords flag will be removed after enough migration time.  Casual use of them will make it difficult to remove, so I'd like to keep them for non-casual use.

(I thought `RubyVM.ruby2_keywords?(hash)` is good but @eregon will be against it :-)

@jeremyevans0 Could you tell me your opinion?



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

  parent reply	other threads:[~2020-01-14  6:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16486.20200106094637@ruby-lang.org>
2020-01-06  9:46 ` [ruby-core:96687] [Ruby master Feature#16486] Hash.ruby2_keywords?(hash) and Hash.ruby2_keywords!(hash) mame
2020-01-06 14:53 ` [ruby-core:96689] [Ruby master Bug#16486] " merch-redmine
2020-01-06 18:10 ` [ruby-core:96691] " eregontp
2020-01-06 23:27 ` [ruby-core:96696] " mame
2020-01-07 14:08 ` [ruby-core:96703] " daniel
2020-01-08 11:19 ` [ruby-core:96710] " eregontp
2020-01-08 23:53 ` [ruby-core:96722] " mame
2020-01-09 10:35 ` [ruby-core:96733] " eregontp
2020-01-14  6:27 ` mame [this message]
2020-01-14  6:47 ` [ruby-core:96838] " mame
2020-01-16  4:28 ` [ruby-core:96877] " matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-83838.20200114062715.658ed762de9c7a22@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).