Skip to content

Commit 3a9c091

Browse files
committed
Simplify Set#inspect output
As Set is now a core collection class, it should have special inspect output. Ideally, inspect output should be suitable to eval, similar to array and hash (assuming the elements are also suitable to eval): set = Set[1, 2, 3] eval(set.inspect) == set # should be true The simplest way to do this is to use the Set[] syntax. This deliberately does not use any subclass name in the output, similar to array and hash. It is more important that users know they are dealing with a set than which subclass: Class.new(Set)[] # this does: Set[] # not: #<Class:0x00000c21c78699e0>[] This inspect change breaks the power_assert bundled gem tests, so add power_assert to TEST_BUNDLED_GEMS_ALLOW_FAILURES in the workflows. Implements [Feature #21389]
1 parent 3b602c9 commit 3a9c091

File tree

16 files changed

+53
-33
lines changed

16 files changed

+53
-33
lines changed

.github/workflows/bundled_gems.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
timeout-minutes: 30
105105
env:
106106
RUBY_TESTOPTS: '-q --tty=no'
107-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
107+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
108108
if: ${{ steps.diff.outputs.gems }}
109109

110110
- name: Commit

.github/workflows/macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
timeout-minutes: 60
147147
env:
148148
RUBY_TESTOPTS: '-q --tty=no'
149-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
149+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
150150
PRECHECK_BUNDLED_GEMS: 'no'
151151
LAUNCHABLE_STDOUT: ${{ steps.launchable.outputs.stdout_report_path }}
152152
LAUNCHABLE_STDERR: ${{ steps.launchable.outputs.stderr_report_path }}

.github/workflows/modgc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
timeout-minutes: ${{ matrix.gc.timeout || 40 }}
154154
env:
155155
RUBY_TESTOPTS: '-q --tty=no'
156-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
156+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
157157
PRECHECK_BUNDLED_GEMS: 'no'
158158
LAUNCHABLE_STDOUT: ${{ steps.launchable.outputs.stdout_report_path }}
159159
LAUNCHABLE_STDERR: ${{ steps.launchable.outputs.stderr_report_path }}

.github/workflows/parse_y.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
EXCLUDES: '../src/test/.excludes-parsey'
8888
RUN_OPTS: ${{ matrix.run_opts || '--parser=parse.y' }}
8989
SPECOPTS: ${{ matrix.specopts || '-T --parser=parse.y' }}
90-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
90+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
9191

9292
- uses: ./.github/actions/slack
9393
with:

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
timeout-minutes: ${{ matrix.timeout || 40 }}
134134
env:
135135
RUBY_TESTOPTS: '-q --tty=no'
136-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
136+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
137137
PRECHECK_BUNDLED_GEMS: 'no'
138138
LAUNCHABLE_STDOUT: ${{ steps.launchable.outputs.stdout_report_path }}
139139
LAUNCHABLE_STDERR: ${{ steps.launchable.outputs.stderr_report_path }}

.github/workflows/yjit-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
timeout-minutes: 60
154154
env:
155155
RUBY_TESTOPTS: '-q --tty=no'
156-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
156+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
157157
SYNTAX_SUGGEST_TIMEOUT: '5'
158158
PRECHECK_BUNDLED_GEMS: 'no'
159159
LAUNCHABLE_STDOUT: ${{ steps.launchable.outputs.stdout_report_path }}

.github/workflows/yjit-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ jobs:
201201
timeout-minutes: 90
202202
env:
203203
RUBY_TESTOPTS: '-q --tty=no'
204-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor'
204+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,rbs,repl_type_completor,power_assert'
205205
PRECHECK_BUNDLED_GEMS: 'no'
206206
SYNTAX_SUGGEST_TIMEOUT: '5'
207207
YJIT_BINDGEN_DIFF_OPTS: '--exit-code'

.github/workflows/zjit-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jobs:
150150
timeout-minutes: 60
151151
env:
152152
RUBY_TESTOPTS: '-q --tty=no'
153-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof'
153+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,power_assert'
154154
SYNTAX_SUGGEST_TIMEOUT: '5'
155155
PRECHECK_BUNDLED_GEMS: 'no'
156156
TESTS: ${{ matrix.tests }}

.github/workflows/zjit-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
timeout-minutes: 90
173173
env:
174174
RUBY_TESTOPTS: '-q --tty=no'
175-
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof'
175+
TEST_BUNDLED_GEMS_ALLOW_FAILURES: 'typeprof,power_assert'
176176
PRECHECK_BUNDLED_GEMS: 'no'
177177
SYNTAX_SUGGEST_TIMEOUT: '5'
178178
ZJIT_BINDGEN_DIFF_OPTS: '--exit-code'

set.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ static int
537537
set_inspect_i(st_data_t key, st_data_t arg)
538538
{
539539
VALUE str = (VALUE)arg;
540-
if (RSTRING_LEN(str) > 8) {
540+
if (RSTRING_LEN(str) > 4) {
541541
rb_str_buf_cat_ascii(str, ", ");
542542
}
543543
rb_str_buf_append(str, rb_inspect((VALUE)key));
@@ -550,10 +550,10 @@ set_inspect(VALUE set, VALUE dummy, int recur)
550550
{
551551
VALUE str;
552552

553-
if (recur) return rb_usascii_str_new2("#<Set: {...}>");
554-
str = rb_str_buf_new2("#<Set: {");
553+
if (recur) return rb_usascii_str_new2("Set[...]");
554+
str = rb_str_buf_new2("Set[");
555555
set_iter(set, set_inspect_i, str);
556-
rb_str_buf_cat2(str, "}>");
556+
rb_str_buf_cat2(str, "]");
557557

558558
return str;
559559
}

0 commit comments

Comments
 (0)