Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, sorting inline tables would throw a ValueError if the key in
the table had trailing spaces.
For example:
Sorting a.b with "d" first would fail.
Removing the space would "pass":
However, when the table was written back out, rerunning toml-sort would
fail because the keys are written with surrounding spaces:
When commit 9900c71 was introduced, the value used for the index
lookup in the list of "first" keys changed to be
Key.as_string()
.The intent was probably to pass type checks as the list of keys are
strings and mypy complains when doing an index lookup that doesn't match
the typing of the list elements (str vs Key).
However,
as_string()
uses the "original" value of the key whichincludes spaces and is subtlely different than the check performed
on the previous line that checked if the value was in the list.
Both the
in
keyword and thelist.index
method use the equalityoperation to evaluate if a value is in a list.
The
Key
object defines the__eq__
method that compares the internalkey value (which is stripped) to the other value. This is why the
in
lookup succeeds but the
index
lookup fails.Now, the lookup logic is simplified.
Instead of potentially searching the list of "first" keys twice, once
via
in
and once vialist.index
, iterate the list viaenumerate
tokeep track of the index and perform an explicit equality check against
Key.key
which appeases mypy.