Fix complex zero-padding error priority by shAn-kor · Pull Request #8453 · RustPython/RustPython · GitHub
Skip to content

Fix complex zero-padding error priority - #8453

Merged
youknowone merged 2 commits into
RustPython:mainfrom
shAn-kor:fix-complex-zero-padding-error-order
Aug 4, 2026
Merged

Fix complex zero-padding error priority#8453
youknowone merged 2 commits into
RustPython:mainfrom
shAn-kor:fix-complex-zero-padding-error-order

Conversation

@shAn-kor

@shAn-kor shAn-kor commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What changed

For complex values, 0 padding and = alignment are both invalid. When a format spec contains both, CPython raises the zero-padding error first. RustPython returned the alignment error in the regular formatting path, and the locale-aware n path applied the checks separately.

The validation now lives in one helper used by both paths. Specs such as =08.1f and =08n report the zero-padding error; =8.1f and =8n still report the alignment error.

The regression tests cover both paths.

Tests

  • cargo test -p rustpython-common format_complex_
  • cargo run --release -- -m test test_complex
  • cargo clippy -p rustpython-common --all-targets -- -D warnings
  • cargo fmt --all -- --check

AI assistance

Codex (GPT-5) assisted with comparing CPython and RustPython behavior, drafting the implementation and regression tests, and writing this PR description.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for complex number formatting options.
    • Consistently rejects unsupported combinations of zero-padding and after-sign alignment in standard and locale-aware formatting.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@shAn-kor
shAn-kor marked this pull request as ready for review August 4, 2026 10:08

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you!

@youknowone
youknowone merged commit 6eea4fd into RustPython:main Aug 4, 2026
27 checks passed
@shAn-kor
shAn-kor deleted the fix-complex-zero-padding-error-order branch August 5, 2026 00:02
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.

2 participants