ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95896] [Ruby master Feature#16356] Method#inspect of argument forwarding
       [not found] <redmine.issue-16356.20191120105811@ruby-lang.org>
@ 2019-11-20 10:58 ` zn
  2019-11-20 20:11 ` [ruby-core:95900] " zverok.offline
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: zn @ 2019-11-20 10:58 UTC (permalink / raw
  To: ruby-core

Issue #16356 has been reported by znz (Kazuhiro NISHIYAMA).

----------------------------------------
Feature #16356: Method#inspect of argument forwarding
https://bugs.ruby-lang.org/issues/16356

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Current behavior includes `(**, &&)`.
Is this intentional?

```
% ruby -e 'def mf(...);end;p method(:mf)'
#<Method: main.mf(**, &&) -e:1>
```

I added tests of current behavior at https://github.com/ruby/ruby/commit/777973084e599cf9efa490173709b187fb507f90



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

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

* [ruby-core:95900] [Ruby master Feature#16356] Method#inspect of argument forwarding
       [not found] <redmine.issue-16356.20191120105811@ruby-lang.org>
  2019-11-20 10:58 ` [ruby-core:95896] [Ruby master Feature#16356] Method#inspect of argument forwarding zn
@ 2019-11-20 20:11 ` zverok.offline
  2019-11-20 20:31 ` [ruby-core:95901] " merch-redmine
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: zverok.offline @ 2019-11-20 20:11 UTC (permalink / raw
  To: ruby-core

Issue #16356 has been updated by zverok (Victor Shepelev).


`#inspect` just follows whatever `#parameters` say. 

But I indeed find that `#parameters` return value is kinda weird for this case:

```
./ruby --disable-gems -e "def m(...); end; p method(:m).parameters"
[[:rest, :*], [:block, :&]]
```
E.g., literally, "parameter of the *type* `:rest`, *named* `*`, and parameter of the *type* `:block`, *named* `&`".

I believe that a proper return value for parameters in this case would be, probably
```ruby
[[:rest], [:keyrest], [:block]]
```
If it would be so (and it seems reasonable), `#inspect` will return `#m(*, **, &)`

----------------------------------------
Feature #16356: Method#inspect of argument forwarding
https://bugs.ruby-lang.org/issues/16356#change-82742

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Current behavior includes `(**, &&)`.
Is this intentional?

```
% ruby -e 'def mf(...);end;p method(:mf)'
#<Method: main.mf(**, &&) -e:1>
```

I added tests of current behavior at https://github.com/ruby/ruby/commit/777973084e599cf9efa490173709b187fb507f90



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

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

* [ruby-core:95901] [Ruby master Feature#16356] Method#inspect of argument forwarding
       [not found] <redmine.issue-16356.20191120105811@ruby-lang.org>
  2019-11-20 10:58 ` [ruby-core:95896] [Ruby master Feature#16356] Method#inspect of argument forwarding zn
  2019-11-20 20:11 ` [ruby-core:95900] " zverok.offline
@ 2019-11-20 20:31 ` merch-redmine
  2019-11-20 20:58 ` [ruby-core:95902] " zverok.offline
  2019-11-21 13:54 ` [ruby-core:95904] " shevegen
  4 siblings, 0 replies; 5+ messages in thread
From: merch-redmine @ 2019-11-20 20:31 UTC (permalink / raw
  To: ruby-core

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


zverok (Victor Shepelev) wrote:
> `#inspect` just follows whatever `#parameters` say. 
> 
> But I indeed find that `#parameters` return value is kinda weird for this case:
> 
> ```
> ./ruby --disable-gems -e "def m(...); end; p method(:m).parameters"
> [[:rest, :*], [:block, :&]]
> ```
> E.g., literally, "parameter of the *type* `:rest`, *named* `*`, and parameter of the *type* `:block`, *named* `&`".
> 
> I believe that a proper return value for parameters in this case would be, probably
> ```ruby
> [[:rest], [:keyrest], [:block]]
> ```
> If it would be so (and it seems reasonable), `#inspect` will return `#m(*, **, &)`

That's not how `...` is implemented, though.  It is implemented so that:

```ruby
def a(...)
  b(...)
end
```

means

```ruby
ruby2_keywords def a(*args, &block)
  b(*args, &block)
end
```

other than the local variable names.  So the current behavior omitting `:keyrest` makes sense.  The local variable names should not be included, so the `parameters` output should probably be `[[:rest], [:block]]`.

This does raise a question of whether methods flagged with `ruby2_keywords` should have their `parameters` output reflect that.  I'm not sure whether that is worth doing, but if so, we should probably replace `:rest` with something like `:restkw`.

----------------------------------------
Feature #16356: Method#inspect of argument forwarding
https://bugs.ruby-lang.org/issues/16356#change-82743

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Current behavior includes `(**, &&)`.
Is this intentional?

```
% ruby -e 'def mf(...);end;p method(:mf)'
#<Method: main.mf(**, &&) -e:1>
```

I added tests of current behavior at https://github.com/ruby/ruby/commit/777973084e599cf9efa490173709b187fb507f90



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

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

* [ruby-core:95902] [Ruby master Feature#16356] Method#inspect of argument forwarding
       [not found] <redmine.issue-16356.20191120105811@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-11-20 20:31 ` [ruby-core:95901] " merch-redmine
@ 2019-11-20 20:58 ` zverok.offline
  2019-11-21 13:54 ` [ruby-core:95904] " shevegen
  4 siblings, 0 replies; 5+ messages in thread
From: zverok.offline @ 2019-11-20 20:58 UTC (permalink / raw
  To: ruby-core

Issue #16356 has been updated by zverok (Victor Shepelev).


@jeremyevans0 thanks for the explanation, I suspected there is something important about missing `:keyrest` there :)
But names (e.g. literal `:*` and `:&`) should be excluded from `parameters` output anyways, right?..

----------------------------------------
Feature #16356: Method#inspect of argument forwarding
https://bugs.ruby-lang.org/issues/16356#change-82744

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Current behavior includes `(**, &&)`.
Is this intentional?

```
% ruby -e 'def mf(...);end;p method(:mf)'
#<Method: main.mf(**, &&) -e:1>
```

I added tests of current behavior at https://github.com/ruby/ruby/commit/777973084e599cf9efa490173709b187fb507f90



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

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

* [ruby-core:95904] [Ruby master Feature#16356] Method#inspect of argument forwarding
       [not found] <redmine.issue-16356.20191120105811@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-11-20 20:58 ` [ruby-core:95902] " zverok.offline
@ 2019-11-21 13:54 ` shevegen
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2019-11-21 13:54 UTC (permalink / raw
  To: ruby-core

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


> But names (e.g. literal :* and :&) should be excluded from parameters output anyways, right?

I am not matz, nor among the core team, but I think that the general intention is that the
information displayed here (e. g. via #inspect) should be useful to the user, to some extent;
and ideally consistent/uniform whenever possible.

As Kazuhiro showed, the display is like:

    #<Method: main.mf(**, &&) -e:1>

And I am not sure if this is that helpful for ruby users. It is also a bit strange that
-e:1 is passed. I can not imagine that this is very useful to anyone. :) This is from
the commandline, yes? I remember having that sometimes when invoking ruby scripts or
e. g. calling a custom method in some .rb file.

So, no matter whether there may be reasons behind the display, I think Kazuhiro's question
is a good one either way how you look at this. (Actually what may be missing in the
issue description is to say what should otherwise be shown, rather than the current
"main.mf(**, &&) -e:1". I guess one could also show more information if wanted or
necessary, such as to indicate that it may be a forwarded-message. Perhaps matz or
nobu may know what might fit best here.)

> So the current behavior omitting :keyrest makes sense.

I think this is only one part; the other is whether this is very useful for ruby 
users. Kazuhiro did not explicitely mention this, but I think the current display
is a bit weird.

----------------------------------------
Feature #16356: Method#inspect of argument forwarding
https://bugs.ruby-lang.org/issues/16356#change-82747

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Current behavior includes `(**, &&)`.
Is this intentional?

```
% ruby -e 'def mf(...);end;p method(:mf)'
#<Method: main.mf(**, &&) -e:1>
```

I added tests of current behavior at https://github.com/ruby/ruby/commit/777973084e599cf9efa490173709b187fb507f90



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

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

end of thread, other threads:[~2019-11-21 13:54 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-16356.20191120105811@ruby-lang.org>
2019-11-20 10:58 ` [ruby-core:95896] [Ruby master Feature#16356] Method#inspect of argument forwarding zn
2019-11-20 20:11 ` [ruby-core:95900] " zverok.offline
2019-11-20 20:31 ` [ruby-core:95901] " merch-redmine
2019-11-20 20:58 ` [ruby-core:95902] " zverok.offline
2019-11-21 13:54 ` [ruby-core:95904] " shevegen

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