-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
pprint
and repr
now sort map keys
#1698
Conversation
This also modifies the |
Regarding the introduction of a |
This change is more invasive than I expected because the existing Elvish value comparison code was in `pkg/eval`. This moves the value comparison logic into `pkg/eval/vals` so it can be used by packges other than `eval`. For example, the vals package `repr` implementation as well as other Elvish modules which may want to compare Elvish values. I also decided to introduce a `strutil.Dedent` function to make it easier to write multiline string literals in unit tests to improve readability of the expected value. This also sorts the keys of pseudo (struct) maps for consistency with mutable maps. This arguably makes the output of pretty-printing pseudo maps less friendly since a struct map definition typically orders its members in a deliberate fashion (unlike a regular map). However, it is more important that the output of printing the output of regular and pseudo maps (via `repr` or `pprint`) be consistent with regard to the order of their keys. Related: elves#1495
e7ba99d
to
778395d
Compare
The Printing maps with ordered keys does not require a total ordering of all values. You can group values by types, and only sort the groups that are actually sortable.
Pseudo maps and maps are already different. I would rather pseudo maps keep their original key order.
A |
If you'd like to continue contributing this change, please break the change that moves You can also leave this feature to me as I have a pretty good idea of how I'd like it to work at this point. |
Neither does the existing Closing this since I'll push an update to PR #1700 that implements the idea in the previous paragraph for the |
This change is more invasive than I expected because the existing Elvish value comparison code was in
pkg/eval
. This moves the value comparison logic intopkg/eval/vals
so it can be used by packges other thaneval
. For example, the vals packagerepr
implementation as well as other Elvish modules which may want to compare Elvish values.I also decided to introduce a
strutil.Dedent
function to make it easier to write multiline string literals in unit tests to improve readability of the expected value.This also sorts the keys of pseudo (struct) maps for consistency with mutable maps. This arguably makes the output of pretty-printing pseudo maps less friendly since a struct map definition typically orders its members in a deliberate fashion (unlike a regular map). However, it is more important that the output of printing the output of regular and pseudo maps (via
repr
orpprint
) be consistent with regard to the order of their keys.Related: #1495