ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
@ 2024-04-17 12:17 tompng (tomoya ishida) via ruby-core
  2024-04-17 17:13 ` [ruby-core:117570] " byroot (Jean Boussier) via ruby-core
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: tompng (tomoya ishida) via ruby-core @ 2024-04-17 12:17 UTC (permalink / raw)
  To: ruby-core; +Cc: tompng (tomoya ishida)

Issue #20433 has been reported by tompng (tomoya ishida).

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:117570] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
@ 2024-04-17 17:13 ` byroot (Jean Boussier) via ruby-core
  2024-04-18  2:43 ` [ruby-core:117585] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2024-04-17 17:13 UTC (permalink / raw)
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20433 has been updated by byroot (Jean Boussier).


An easy fix would be for `Hash#inspect` to include spaces around `=>`. It would also read much nicer in my opinion.

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-107967

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:117585] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
  2024-04-17 17:13 ` [ruby-core:117570] " byroot (Jean Boussier) via ruby-core
@ 2024-04-18  2:43 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-04-18  3:16 ` [ruby-core:117587] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-04-18  2:43 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20433 has been updated by nobu (Nobuyoshi Nakada).


Or use `{a!: 1}` for symbol keys?

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-107985

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:117587] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
  2024-04-17 17:13 ` [ruby-core:117570] " byroot (Jean Boussier) via ruby-core
  2024-04-18  2:43 ` [ruby-core:117585] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-04-18  3:16 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-05-07 19:01 ` [ruby-core:117795] " jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-04-18  3:16 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20433 has been updated by nobu (Nobuyoshi Nakada).


Ditto for pp.rb.

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-107987

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:117795] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (2 preceding siblings ...)
  2024-04-18  3:16 ` [ruby-core:117587] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-05-07 19:01 ` jeremyevans0 (Jeremy Evans) via ruby-core
  2024-05-07 20:44 ` [ruby-core:117797] " Eregon (Benoit Daloze) via ruby-core
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2024-05-07 19:01 UTC (permalink / raw)
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

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


I submitted a pull request for the most backwards compatible change, which only uses spaces around `=>` for symbols ending in `[!?*=<]`: https://github.com/ruby/ruby/pull/10737

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-108201

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:117797] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (3 preceding siblings ...)
  2024-05-07 19:01 ` [ruby-core:117795] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2024-05-07 20:44 ` Eregon (Benoit Daloze) via ruby-core
  2024-05-08 12:24 ` [ruby-core:117811] " Dan0042 (Daniel DeLorme) via ruby-core
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-05-07 20:44 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


I think always having spaces would help readability.
If we don't want to change that, then how about simply quoting these symbols that need it?

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-108203

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:117811] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (4 preceding siblings ...)
  2024-05-07 20:44 ` [ruby-core:117797] " Eregon (Benoit Daloze) via ruby-core
@ 2024-05-08 12:24 ` Dan0042 (Daniel DeLorme) via ruby-core
  2024-06-06  9:27 ` [ruby-core:118201] " mame (Yusuke Endoh) via ruby-core
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2024-05-08 12:24 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

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


> If we don't want to change that, then how about simply quoting these symbols that need it?

+1



----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-108220

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:118201] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (5 preceding siblings ...)
  2024-05-08 12:24 ` [ruby-core:117811] " Dan0042 (Daniel DeLorme) via ruby-core
@ 2024-06-06  9:27 ` mame (Yusuke Endoh) via ruby-core
  2024-06-06 17:49 ` [ruby-core:118219] " tompng (tomoya ishida) via ruby-core
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-06-06  9:27 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

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


Discussed at the dev meeting.

In conclusion, @matz wanted to change the return value of `Hash#inspect` significantly and estimate its compatibility impact:

```ruby
{ :key => 42 }  #=> {key: 42}     # if the key is a symbol
{ :== => 42 }   #=> {"==": 42}    # if the key is a symbol and quotes are needed
{ "str" => 42 } #=> {"str" => 42} # otherwise (note that `=>` is surrounded by spaces)

# when keys are mixed
{ :== => 1, :key => 2, "str" => 3 } # {"==": 1, key: 2, "str" => 3}
```

Actually, some solutions were discussed.

Solution 1: insert a space before `=>` only when needed.
```ruby
{ :key => 1 } # {:key=>1}
{ :== => 1 }  # {:== =>1}
{ :a! => 1 }  # {:a! =>1}
```

Solution 2: insert spaces before and after `=>` consistently
```ruby
{ :key => 1 } # {:key => 1}
{ :== => 1 }  # {:== => 1}
{ :a! => 1 }  # {:a! => 1}
```

Solution 3: quote keys only when needed
```ruby
{ :== => 1 }  # {:"=="=>1}
{ :a! => 1 }  # {:"a!"=>1}
{ :key => 1 } # {:key=>1}
```

Matz said he likes Solution 2. However, this has a compatibility issue. It may break some existing test assertions.

Matz had had the idea of denoting symbol keys by a colon in `Hash#inspect`. And the incompatibility impacts of Solution 2 and of symbol keys by colons are expected to be about the same. Rather than introducing the incompatibilities in two steps, Matz said he wants to change it at once.

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-108688

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:118219] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (6 preceding siblings ...)
  2024-06-06  9:27 ` [ruby-core:118201] " mame (Yusuke Endoh) via ruby-core
@ 2024-06-06 17:49 ` tompng (tomoya ishida) via ruby-core
  2024-06-14 15:14 ` [ruby-core:118319] " tompng (tomoya ishida) via ruby-core
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tompng (tomoya ishida) via ruby-core @ 2024-06-06 17:49 UTC (permalink / raw)
  To: ruby-core; +Cc: tompng (tomoya ishida)

Issue #20433 has been updated by tompng (tomoya ishida).


I created a proof of concept patch for colon style inspect https://github.com/ruby/ruby/pull/10924

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-108707

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:118319] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (7 preceding siblings ...)
  2024-06-06 17:49 ` [ruby-core:118219] " tompng (tomoya ishida) via ruby-core
@ 2024-06-14 15:14 ` tompng (tomoya ishida) via ruby-core
  2024-07-23  2:34 ` [ruby-core:118668] " matz (Yukihiro Matsumoto) via ruby-core
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tompng (tomoya ishida) via ruby-core @ 2024-06-14 15:14 UTC (permalink / raw)
  To: ruby-core; +Cc: tompng (tomoya ishida)

Issue #20433 has been updated by tompng (tomoya ishida).


I investigated the impact to ruby ci.

Need to update these tests. The required change was within the expected range.
~~~
bootstraptest
test/coverage
test/error_highlight
test/rdoc
test/reline
test/ruby
test/rubygems
spec/bundler
spec/ruby
~~~

Two bundled gem tests failed.
~~~
minitest (4 failure)
debug (2 failure)
~~~
All of them passes by only changing the expected string/regexp from `key=>value` to `key => value` or `:key=>value` to `key: value`.

## Test against several ruby versions
Test of mspec, default gems and bundled gems needs to pass in several ruby versions.
In most case, changing `expected = "message {1=>2}"` to `expected = "message #{{1=>2}.inspect}"` was enough.

There are some case that needs a little more effort like this.
~~~ruby
# spec/ruby/core/string/modulo_spec.rb
{ a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/

# spec/ruby/library/net-http/http/send_request_spec.rb
response.body.should include('"Referer"=>"' + referer + '"')

# minitst/minitest test/minitest/test_minitest_mock.rb
exp = "expected foo(:kw=>false) => nil, got [foo(:kw=>true) => nil]"
~~~

@matz For your information


----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-108827

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



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

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

* [ruby-core:118668] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (8 preceding siblings ...)
  2024-06-14 15:14 ` [ruby-core:118319] " tompng (tomoya ishida) via ruby-core
@ 2024-07-23  2:34 ` matz (Yukihiro Matsumoto) via ruby-core
  2024-07-23  5:53 ` [ruby-core:118669] " zverok (Victor Shepelev) via ruby-core
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2024-07-23  2:34 UTC (permalink / raw)
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

Issue #20433 has been updated by matz (Yukihiro Matsumoto).


IMO, this is a good chance to upgrade Hash#inspect format to adopt current Hash usage.

* symbol keys should be represented by "`key:`"
* ambiguous keys should be wrapped by (double) quotation marks
* spaces should be placed after "`:`" and around "`=>`".

I'd propose that we try new format for release candidates. If serious compatibility issues happen (although I don't believe we will see), we re-consider this change again.

Matz.


----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-109200

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:118669] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (9 preceding siblings ...)
  2024-07-23  2:34 ` [ruby-core:118668] " matz (Yukihiro Matsumoto) via ruby-core
@ 2024-07-23  5:53 ` zverok (Victor Shepelev) via ruby-core
  2024-07-24 19:00 ` [ruby-core:118679] " vo.x (Vit Ondruch) via ruby-core
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2024-07-23  5:53 UTC (permalink / raw)
  To: ruby-core; +Cc: zverok (Victor Shepelev)

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


> ambiguous keys should be wrapped by (double) quotation marks

BTW, if the change is so radical, can we also (start to) adopt Python’s flexible quotation marks? (For now, only for Hash keys, but once, maybe, for strings):

```python
print("test 'quotes'".__repr__())
#=> "test 'quotes'"

print('test "quotes"'.__repr__())
#=> 'test "quotes"'
```

I.e. make it so for Hash keys:
```ruby
{"'": true, '"': false}.inspect
#=> {"'": true, '"': false}
```

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-109202

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:118679] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (10 preceding siblings ...)
  2024-07-23  5:53 ` [ruby-core:118669] " zverok (Victor Shepelev) via ruby-core
@ 2024-07-24 19:00 ` vo.x (Vit Ondruch) via ruby-core
  2024-10-03 15:49 ` [ruby-core:119434] " byroot (Jean Boussier) via ruby-core
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: vo.x (Vit Ondruch) via ruby-core @ 2024-07-24 19:00 UTC (permalink / raw)
  To: ruby-core; +Cc: vo.x (Vit Ondruch)

Issue #20433 has been updated by vo.x (Vit Ondruch).


matz (Yukihiro Matsumoto) wrote in #note-10:
> IMO, this is a good chance to upgrade Hash#inspect format to adopt current Hash usage.
> 
> * symbol keys should be represented by "`key:`"


I wish we stayed with the hash rockets, sigh

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-109216

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:119434] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (11 preceding siblings ...)
  2024-07-24 19:00 ` [ruby-core:118679] " vo.x (Vit Ondruch) via ruby-core
@ 2024-10-03 15:49 ` byroot (Jean Boussier) via ruby-core
  2024-10-03 16:04 ` [ruby-core:119435] " mame (Yusuke Endoh) via ruby-core
  2024-10-05 17:02 ` [ruby-core:119465] " byroot (Jean Boussier) via ruby-core
  14 siblings, 0 replies; 16+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2024-10-03 15:49 UTC (permalink / raw)
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20433 has been updated by byroot (Jean Boussier).


@tompng @mame what is the status on this? I see https://github.com/ruby/ruby/pull/10924 has been merged, should this ticket be closed?

I personally love this change, but I have a lot of tests to update as a result, so I'd like to know if this is certain this change will be part of 3.4.0 before I start the work of fixing it all. 

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-110054

* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:119435] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (12 preceding siblings ...)
  2024-10-03 15:49 ` [ruby-core:119434] " byroot (Jean Boussier) via ruby-core
@ 2024-10-03 16:04 ` mame (Yusuke Endoh) via ruby-core
  2024-10-05 17:02 ` [ruby-core:119465] " byroot (Jean Boussier) via ruby-core
  14 siblings, 0 replies; 16+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-10-03 16:04 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

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

Status changed from Open to Closed

Yes, I have merged it since @matz said at the dev meeting today that he still wants to try this change in the next preview release. So closing.

However, it may be reverted if the impact of the incompatibility is too large.

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-110055

* Author: tompng (tomoya ishida)
* Status: Closed
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:119465] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
  2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
                   ` (13 preceding siblings ...)
  2024-10-03 16:04 ` [ruby-core:119435] " mame (Yusuke Endoh) via ruby-core
@ 2024-10-05 17:02 ` byroot (Jean Boussier) via ruby-core
  14 siblings, 0 replies; 16+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2024-10-05 17:02 UTC (permalink / raw)
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20433 has been updated by byroot (Jean Boussier).


To provide some datapoint, here's the impact on Rails test suite: https://github.com/rails/rails/pull/53202

I still love the change, and it really wasn't much work to fix, but I fear we may hear some complaints.

----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-110083

* Author: tompng (tomoya ishida)
* Status: Closed
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}
~~~
`eval(hash.inspect)` will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2024-10-05 17:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 12:17 [ruby-core:117564] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation tompng (tomoya ishida) via ruby-core
2024-04-17 17:13 ` [ruby-core:117570] " byroot (Jean Boussier) via ruby-core
2024-04-18  2:43 ` [ruby-core:117585] " nobu (Nobuyoshi Nakada) via ruby-core
2024-04-18  3:16 ` [ruby-core:117587] " nobu (Nobuyoshi Nakada) via ruby-core
2024-05-07 19:01 ` [ruby-core:117795] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-05-07 20:44 ` [ruby-core:117797] " Eregon (Benoit Daloze) via ruby-core
2024-05-08 12:24 ` [ruby-core:117811] " Dan0042 (Daniel DeLorme) via ruby-core
2024-06-06  9:27 ` [ruby-core:118201] " mame (Yusuke Endoh) via ruby-core
2024-06-06 17:49 ` [ruby-core:118219] " tompng (tomoya ishida) via ruby-core
2024-06-14 15:14 ` [ruby-core:118319] " tompng (tomoya ishida) via ruby-core
2024-07-23  2:34 ` [ruby-core:118668] " matz (Yukihiro Matsumoto) via ruby-core
2024-07-23  5:53 ` [ruby-core:118669] " zverok (Victor Shepelev) via ruby-core
2024-07-24 19:00 ` [ruby-core:118679] " vo.x (Vit Ondruch) via ruby-core
2024-10-03 15:49 ` [ruby-core:119434] " byroot (Jean Boussier) via ruby-core
2024-10-03 16:04 ` [ruby-core:119435] " mame (Yusuke Endoh) via ruby-core
2024-10-05 17:02 ` [ruby-core:119465] " byroot (Jean Boussier) via ruby-core

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 NNTP newsgroup(s).