Skip to content

Align builtin behavior and atexit callbacks with CPython - #9442

Merged
youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:fix/function-code-kind-warning-20261028
Oct 29, 2026
Merged

youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:fix/function-code-kind-warning-20261028

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Match CPython 3.15's complex constructor routes: single-positional conversion versus real/imag components, including deprecation warnings and conversion/error priority.
  • Warn before replacing a function's code with a different generator/coroutine kind, after validating its closure requirements and before mutation/JIT locking.
  • Match float power's full special-value ordering: zero exponents, NaNs, infinite exponents/bases, signed zero, finite negative fractional bases, exact odd parity, and signed underflow.
  • Preserve the complete atexit callback snapshot through execution, report SystemExit and continue to later callbacks, and clear the live registry afterward. Release callback entries in reverse order and outside the registry mutex.
  • Retire the three corresponding expected-failure decorators through actual update_lib migrations. test_complex.py, test_funcattrs.py, and test_float.py match CPython d220409a13b77de7a6c30abe16ea90db01528edc exactly.

The complex conversion helper retains its returned object through argument validation and releases it before the original-real capability check/warning. Other try_complex callers retain their prior scalar conversion behavior. Existing signed-zero, exact-complex identity, closure, and JIT guards are preserved.

The float helper deliberately overlaps #8624's partial float-power correction: its numeric negativity and exact fractional classification are subsumed by the complete CPython special-value ordering. This does not incorporate or modify that PR's separate JIT changes. Finite overflow still raises OverflowError with RustPython's existing math range error text rather than CPython's errno-derived arguments/message; platform-libm diagnostic equivalence is not claimed.

Validation

  • Fresh scoped cargo check and strict cargo clippy -- -Dwarnings passed; one guarded native build passed.
  • Combined protected native executable built from base 8c6c94b07174224517b6bf62abab202565382ea7 plus this branch’s complex-constructor, function-code-warning, and float-power native changes: SHA-256 4b4b55bfffd0ba5a691efb6cc8b14aea8ca70976846f7951d07e41dc427b344a. All 23 recorded source hashes verified before/after build; protected binary verified at runtime.
  • Complex: eight unmodified canonical constructor/conversion methods and nine finite warning/order/identity oracles passed (17 total).
  • Function assignment: full canonical test_invalid___code___assignment and four finite warning/error-order oracles passed (5 total).
  • Float power: full unmodified canonical GeneralFloatCases.test_float_pow and four finite special-value/sign/error-priority oracle groups passed (5 total). The complete updater-generated method also passed separately.
  • All 27 combined native tests and the generated-method check passed without skips or expected failures. Matching host CPython runs passed the corresponding 17 + 5 + 5 tests.
  • Updater self-tests passed: 228 tests with PYTHONPATH=scripts.
  • Applicable configured hooks passed, including rustfmt, Ruff, cspell, and redundant-patch checks; diff checks passed.

This is focused constructor, code-assignment, and float-power compatibility evidence, not a claim that all arithmetic, JIT execution, or Python 3.15 behavior was tested. No full-module/workspace/CAPI, concurrency, crash, GC, profiler, or stress suites were run for this follow-up.

Atexit follow-up and combined validation

The callback-only follow-up is applied to head 4fc9eca9fdbb8fa3860371489302783ce62d51d4 without changing its existing native or Lib updates. Fresh scoped check and strict Clippy passed. One completed guarded recovery build produced protected executable SHA-256 37e950d1aead31f11b49092c862f232bcf703a4acd940e1f888e6662e03cf04d; all 607 native inputs, retained source timestamps, compiler artifact provenance and 12 runtime inputs were verified.

All 36 tests passed on that same combined executable: the 17 complex, 5 function-assignment and 5 float cases above, plus eight unchanged canonical test._test_atexit.GeneralTest methods and one bounded ordinary Python SystemExit-continuation check. Exact counts were enforced with no skips or expected failures. Earlier interrupted builds have unknown outcomes and supply no success evidence.

This does not implement CPython's repeated finalization quiescence loop, change atexit Lib files, retire atexit markers or enable its new threading tests. Existing callback-entry field destruction layout and low-memory behavior are not asserted identical. No concurrency, GC, destructor-reentry, process-shutdown, profiler or stress tests were executed. The finalization/TLS changes owned by #8939 and #8944 remain separate; this patch does not import or modify them.

AI assistance

OpenAI Codex assisted with implementation, source review, validation, and this description.

Preserve constructor conversion and warning priority, and validate code kinds before assignment. Retire two canonical test markers after focused native verification.

Assisted-by: OpenAI Codex: model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] test: cpython/Lib/test/test_complex.py

dependencies:

dependent tests: (no tests depend on complex)

[x] test: cpython/Lib/test/test_funcattrs.py

dependencies:

dependent tests: (no tests depend on funcattrs)

[x] test: cpython/Lib/test/test_float.py
[x] test: cpython/Lib/test/test_strtod.py

dependencies:

dependent tests: (no tests depend on float)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Handle NaNs, infinities, signed zero, exact fractional exponents, and signed underflow before generic finite power. Retire the canonical float-power expected-failure marker through update_lib after native verification.

Assisted-by: OpenAI Codex: model version unavailable
@youknowdot youknowdot changed the title Align complex construction and code-assignment warnings with CPython Align builtin construction, code warnings, and float power with CPython Oct 28, 2026
@codspeed

codspeed Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix/function-code-kind-warning-20261028 (413d555) with main (8c6c94b)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Assisted-by: OpenAI Codex: model version unavailable
@youknowdot youknowdot changed the title Align builtin construction, code warnings, and float power with CPython Align builtin behavior and atexit callbacks with CPython Oct 28, 2026
@youknowone
youknowone marked this pull request as ready for review October 29, 2026 01:01
@youknowone
youknowone merged commit a1f3d54 into RustPython:main Oct 29, 2026
30 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T01:02:40.373859Z
We couldn’t complete this review. Comment @codex review to try again.
413d555 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

3 participants