-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Simplify Set#inspect output #13488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Simplify Set#inspect output #13488
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should show the subclass name: https://bugs.ruby-lang.org/issues/21389?next_issue_id=21388&prev_issue_id=21390#note-2
I don't understand how you think it's a good idea to mislead the user and show in inspect code which wouldn't reproduce a corresponding instance.
Obviously Module and Object don't do that.
The subclass might have extra methods etc which means recreating a normal Set instead would be incompatible.
This is not misleading the user any more than Whether to use the subclass name is Matz's decision. If he decides to use the subclass name, then I'll update this accordingly.
They follow
Same is true for Hash and Array. |
It is, showing the wrong class name is more misleading than showing no class name.
Yes, agreed, but we don't have that and I think it's not likely to happen (
Yep, agreed that's a good |
Ah I missed (not really, it was written after) https://bugs.ruby-lang.org/issues/21389#note-3, that settles it then |
|
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]
Fixes [Bug #21377] Co-authored-by: zzak <zzak@hey.com>
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):
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:
This inspect change breaks the power_assert bundled gem tests, so add power_assert to TEST_BUNDLED_GEMS_ALLOW_FAILURES in the workflows.