Repository navigation
Align numeric conversion and rounding boundaries - #9697
Draft
youknowdot wants to merge 5 commits into
Draft
youknowdot wants to merge 5 commits into
youknowdot wants to merge 5 commits into
Conversation
Reuse native converters and binding while preserving subclass dispatch, scalar identity, literal normalization, and argument lifetimes. Assisted-by: OpenAI Codex:model version not exposed
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Use exact ties-even rounding and native overflow text, and saturate arbitrary nonnegative step indices through the shared nextafter helper. Assisted-by: OpenAI Codex:model version not exposed
Reuse special-method lookup and native scalar conversion, preserve fsum iteration and allocation ordering, and retain WTF-8 formatting for shared-name consumers. Assisted-by: OpenAI Codex:model version not exposed
Use a closure for the generic fsum callback without changing iterator ownership or numeric behavior. Assisted-by: OpenAI Codex:model version not exposed
Retain generic buffer exports through representation while allowing callback mutation after native parsing finishes. Assisted-by: OpenAI Codex:model version not exposed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Group CPython 3.15 numeric conversion boundaries in 433 changed production lines (+219/-214):
Reuse ArgIntoFloat and ArgIntoComplex to distinguish native scalar conversion from constructor dispatch. Native conversion reads stored float/complex subclass values while constructor-specific special methods retain their required precedence.
Normalize float.real/conjugate results and preserve exact complex.complex identity through existing number helpers.
Match complex special-method error/warning diagnostics with the shared qualified-type formatter.
Normalize Unicode literals before underscore validation, preserve invalid-scalar prefixes, and match embedded-NUL/underscore diagnostics without trimming away information needed by the existing transformer.
Replace float subclass's manual positional parser with the existing FuncArgs binder, retaining original positional and keyword owners through conversion/allocation.
Release bytearray and generic buffer data guards before invalid float literal repr callbacks, while keeping generic buffer exports alive through error construction. This permits callback mutation without deadlocking and preserves export-related resize rejection. The shared C-API float parser benefits from the same fix.
Seven Rust files only. No Python, Lib, tests, expected-failure markers, or workflows changed.
Use exact ties-even float rounding, match decimal-round overflow text, and accept arbitrary nonnegative nextafter step indices through the existing saturated native helper.
Reuse native conversion for log/log2/log10, preserving huge-integer retry behavior. Share ceil/floor conversion and descriptor-miss handling with trunc through existing special-method lookup.
Stream fsum conversions through the existing numerical algorithm, stop before later callbacks after intermediate overflow, and allocate the result before releasing the iterator.
Keep numeric diagnostics/warnings compatible with the shared WTF-8 formatter without duplicating type-name logic.
Reference and validation
Compared with CPython commit d220409a13b77de7a6c30abe16ea90db01528edc: complex conversion, float conversion, and numeric underscore parsing.
13,787 bounded CPython/source-model assertions passed across scalar callbacks, warnings, errors, identities, owner cleanup, Unicode strings and all four shared normalizer consumers. Independent review added 112 CPython observations and 78 NUL boundary assertions, and found a Unicode/NUL diagnostic regression in the initial candidate that is corrected in this final composition. These are reference/model checks, not execution of the Rust implementation.
The rounding companion passed 53,508 further CPython/source-model checks and 116,945 independent assertions using separate integer-round, rational decimal-round and signed-rank nextafter models. These cover signed zero, NaN payloads, infinity, adjacent-to-half floats, bounded huge indices, and error/callback ordering. Independent composition review verified the original conversion group is unchanged outside the narrow companion hunks.
The native math companion passed 4,195 additional bounded CPython/source-model comparisons and 39 independent checks against mathmodule.c. Exact review verified original conversion/rounding content outside intended hunks and compatibility with #9666.
Independent exact-source review passed. Final focused host-env/VM/stdlib threading cargo check, normal all-targets Clippy and ordinary commit hooks passed. Clippy emitted exactly four unchanged main-baseline diagnostics: one POSIX needless-collect and three ElementTree lints. Strict -D warnings remains blocked by that baseline; no warnings were suppressed. No native RustPython execution was attempted. Full workspace/C-API suites and cross-platform runtime checks remain unrun; hosted CI is required.
The buffer-callback follow-up passed 35 bounded pinned-CPython assertions covering bytearray mutation/reentry, generic export retention, Python buffer release order, repr exceptions and success/failure cleanup. Exact-source independent review confirmed that all data guards end before callbacks while export ownership survives error creation. Final follow-up threaded cargo check passed in 1m05s and all-targets Clippy in 2m14s, with exactly the same four baseline diagnostics. Normal commit hooks and diff checks passed. Native RustPython and C-API runtime execution remain unrun; hosted validation is pending.
Remaining limits
The existing ordinary float constructor's keyword-versus-arity diagnostic precedence remains outside this conversion group. Formatting consumers now preserve WTF-8; the shared helper migration itself is tracked in #9700. Native float conversion still has its existing missing-type-name precision difference for unusually long names. Other numeric arithmetic and extreme allocating integer-round behavior remain outside scope. No runtime expected failure is claimed resolved without execution.
AI-assisted contribution by OpenAI Codex, disclosed in the commit trailer.