Implement negative zero coercion formatting - #8475
Conversation
Assisted-by: Codex:gpt-5
Assisted-by: Codex:GPT-5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe formatting engine now parses the ChangesNegative-zero coercion
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant PythonCode
participant FormatSpec
participant FloatOrComplexFormatter
participant VMExceptionMapper
PythonCode->>FormatSpec: parse format specification with z
FormatSpec->>FloatOrComplexFormatter: provide no_neg_0
FloatOrComplexFormatter-->>PythonCode: format zero without negative sign
FormatSpec->>VMExceptionMapper: report unsupported coercion type
VMExceptionMapper-->>PythonCode: raise ValueError
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/reprlib.py dependencies:
dependent tests: (245 tests)
[x] test: cpython/Lib/test/test_funcattrs.py (TODO: 2) dependencies: dependent tests: (no tests depend on funcattrs) [x] test: cpython/Lib/test/test_format.py (TODO: 3) dependencies: dependent tests: (no tests depend on format) Legend:
|
Assisted-by: Codex:gpt-5
Related to #6839
What changed
RustPython did not support the
zformat option introduced by PEP 682, which removes the sign from a negative value when its formatted result rounds to zero.The formatter now parses
zafter the sign option and applies it to floating point and complex formatting, including the locale-awarenpath. The sign is removed only when the formatted magnitude is zero, so-0.0001formatted withz.2fbecomes0.00while nonzero negative results keep their sign.Invalid uses with integer, boolean, and string formats follow CPython error behavior. Complex formatting also preserves explicit
+and space signs for purely imaginary values.The existing
test_negative_zeroCPython test is now enabled, with additional common-layer coverage for rounding, complex values, locale formatting, and invalid format specifications.Tests
cargo test -p rustpython-common format_negative_zero_coercioncargo run --release -- -m test test_formatcargo run --release -- -m test test_complexprek run --all-filesAI assistance
Codex (GPT-5) assisted with comparing CPython and RustPython behavior, drafting the implementation and regression tests, and writing this PR description. I reviewed the final diff and verified the behavior locally.
Summary by CodeRabbit