Skip to content

Fix literal wrapping with black profile#2535

Open
paulkagiri wants to merge 2 commits into
PyCQA:mainfrom
paulkagiri:fix-literal-black-profile-wrapping
Open

Fix literal wrapping with black profile#2535
paulkagiri wants to merge 2 commits into
PyCQA:mainfrom
paulkagiri:fix-literal-black-profile-wrapping

Conversation

@paulkagiri
Copy link
Copy Markdown

Summary

  • account for the assignment prefix when formatting sorted literals
  • use vertical hanging wrapping with trailing commas for black-style literal sorting
  • add regression coverage for tuple sorting with the black profile

Fixes #1815

Tests

  • python -m pytest tests/unit/test_literal.py -q
  • python -m black --target-version py312 --check isort/literal.py tests/unit/test_literal.py
  • python -m ruff check isort/literal.py tests/unit/test_literal.py
  • git diff --check

@DanielNoord
Copy link
Copy Markdown
Member

Please ensure CI passes before opening pull requests :)

@paulkagiri
Copy link
Copy Markdown
Author

Addressed the CI failures.

Changes made:

  • Replaced the dynamic enum attribute access that failed mypy with a type-checker-friendly comparison.
  • Applied the repo formatter (ruff format) to the touched files.
  • Removed an assert in parser code that Bandit flagged during the lint tox env, while keeping the type narrowing explicit through literal straight / lazy_straight branches.

Validation:

  • python -m uv run --with tox-uv tox -e lint
  • python -m uv run --with tox-uv tox -e py
  • python -m pytest tests/unit/test_literal.py -q
  • python -m ruff format --check isort/literal.py tests/unit/test_literal.py
  • git diff --check

@DanielNoord
Copy link
Copy Markdown
Member

@paulkagiri Unfortunately it doesn't pass CI again. Are you sure all code added is covered?

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.

Tuple sorting doesn't consider profile

2 participants