Skip to content

Avoid C414 for stable multi-key sorted calls - #662

Open
onuracar-dev wants to merge 1 commit into
adamchainz:mainfrom
onuracar-dev:fix/flake8-comprehensions-661
Open

Avoid C414 for stable multi-key sorted calls#662
onuracar-dev wants to merge 1 commit into
adamchainz:mainfrom
onuracar-dev:fix/flake8-comprehensions-661

Conversation

@onuracar-dev

Copy link
Copy Markdown

Fixes #661.

Summary

  • Do not emit C414 for sorted(sorted(...), key=<non-None>): Python's stable sort allows the inner sort to establish a secondary ordering.
  • Conservatively avoid C414 when an outer ** expansion may provide the key.
  • Preserve C414 for key=None and the existing genuinely redundant cases.
  • Document the exception in the C414 reference and unreleased changelog.

Validation

  • Upstream regression: the new explicit-key case failed with the reported C414 diagnostic before the fix.
  • Expansion regressions: the **kwargs and literal **{"key": len} cases also failed before their guard was added.
  • Focused C414 tests: 25 passed, 126 deselected.
  • Full suite with ResourceWarning, DeprecationWarning, and PendingDeprecationWarning promoted to errors: 151 passed.
  • pre-commit run --all-files: all hooks passed, including RST checks, Ruff, formatting, and MyPy.
  • uv build: wheel and sdist built successfully.
  • git diff --check and staged secret scan: passed.

AI disclosure: OpenAI Codex (GPT-5) analyzed the issue and generated/revised the implementation, tests, documentation, changelog text, commit message, and this pull-request description. Independent Codex review passes found and corrected a remaining **kwargs false positive before publication, then re-reviewed the final commit and validation results. No separate human review is being represented here.

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.

C414: false positive

1 participant