Repository navigation
Commit 8ba942f
committed
Fix item() reordering dict keys inside inline tables
The list-of-dicts branch of item() builds each dict's sort key as
(isinstance(i[1], dict), i[0] if _sort_keys else 1). The closing
parenthesis only wraps i[0], so the dict-valued check stays active no
matter what _sort_keys is, quietly moving dict-valued keys to the end
even when the caller asked to keep their original order.
For a concrete [table] or array of tables this went unnoticed because
Container.append already repositions scalar keys ahead of any table
header on insertion, independent of the order item() hands it keys in.
Inline tables get no such correction, so the reordering is directly
visible there, e.g. item([1, {"a": {"x": 1}, "b": 2}]) rendered
{b = 2, a = {x = 1}} instead of preserving the original a, b order.
Move the parenthesis to match the sibling top-level dict branch a few
lines above, which already guards the whole tuple correctly. Verified
against the full existing test suite (all 378 tests still pass) plus a
new regression test covering both the default order-preserving case and
sort_keys=True still forcing dict-valued keys last.
Resolves #546.1 parent 8c959b5 commit 8ba942f
3 files changed
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
657 | 674 | | |
658 | 675 | | |
659 | 676 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
0 commit comments