Skip to content

Support f-strings in sorted literals - #2716

Open
SIBTAIN-ASAD wants to merge 1 commit into
PyCQA:mainfrom
SIBTAIN-ASAD:issue/2712-fstring-literals
Open

SIBTAIN-ASAD wants to merge 1 commit into
PyCQA:mainfrom
SIBTAIN-ASAD:issue/2712-fstring-literals

Conversation

@SIBTAIN-ASAD

Copy link
Copy Markdown

Closes #2712.

# isort: list currently relies on ast.literal_eval, so a list containing an f-string fails before it can be sorted.

This change:

  • preserves each f-string's original source while deriving a sortable key from its rendered content;
  • applies the same ordering path to list, unique-list, set, and tuple literals;
  • adds direct and end-to-end regression coverage for the __lazy_modules__ example.

Verification:

  • uv run pytest tests/unit -q --benchmark-disable (675 passed, 1 skipped)
  • uv run ruff check isort/literal.py tests/unit/test_literal.py tests/unit/test_isort.py
  • uv run ruff format --check isort/literal.py tests/unit/test_literal.py tests/unit/test_isort.py
  • uv run mypy isort/literal.py
  • uv run flake8 isort/literal.py tests/unit/test_literal.py tests/unit/test_isort.py

@SIBTAIN-ASAD

SIBTAIN-ASAD commented Oct 7, 2026 •

Copy link
Copy Markdown
Author

I checked the failed Read the Docs build log. It stopped during the initial fetch with fatal: couldn't find remote ref pull/2716/head, before installing dependencies or building the docs. The build is tied to head c5a4c8d3 and appears to be a transient PR-ref fetch failure rather than a Sphinx or code failure. The other recent isort PR docs builds are passing. A Read the Docs rebuild of this PR should confirm that; I am leaving the tested source change unchanged.

This branch has not been deployed

No deployments
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.

Support f-strings when sorting literals

1 participant