Skip to content

fix: correct misplaced parenthesis in item() sort key#554

Closed
muhamedfazalps wants to merge 1 commit into
python-poetry:masterfrom
muhamedfazalps:fix/item-sort-key-parenthesis
Closed

fix: correct misplaced parenthesis in item() sort key#554
muhamedfazalps wants to merge 1 commit into
python-poetry:masterfrom
muhamedfazalps:fix/item-sort-key-parenthesis

Conversation

@muhamedfazalps

Copy link
Copy Markdown

Fixes #546

Corrected a misplaced parenthesis in the sort key lambda for dict-valued list items. All 355 tests pass.

The sort key lambda for dict-valued list items had a misplaced
parenthesis: the isinstance(i[1], dict) check was applied even
when _sort_keys=False, causing dict-valued keys to be silently
reordered after scalar-valued keys regardless of the sort_keys
setting.

Fix: guard the entire sort tuple with _sort_keys, matching the
existing pattern used for top-level dicts (line 146).

Fixes python-poetry#546.
@dimbleby

dimbleby commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

this was wrong at #547 and is still wrong here

@muhamedfazalps

Copy link
Copy Markdown
Author

You're right @dimbleby — the dictionaries-last ordering is intentional capture-avoidance (scalar keys must render before sub-table headers to prevent capture). Making it conditional on sort_keys breaks that invariant. This PR is wrong, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

item() reorders keys (dict-valued before scalar) even with the default sort_keys=False

2 participants