Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Validate text codec names in development mode - #9481

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:py315-dev-codec-preflight-20261030
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:py315-dev-codec-preflight-20261030

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

  • Validate text encoding and error-handler names before fast paths and empty-input returns in -X dev mode, matching CPython's unicode_check_encoding_errors lookup order and common-name shortcuts.
  • Enable this validation only after RustPython's core codec bootstrap succeeds, before stdio setup, and suppress it during interpreter finalization. RustPython has no separate filesystem-codec initialization object, so the bootstrap boundary is documented explicitly.
  • Restore the existing bytes/bytearray and str encoding-error checks using scripts/update_lib migrate from CPython d220409a13b77de7a6c30abe16ea90db01528edc.

General codecs.encode/decode, private Python helpers, normal-mode lazy error-handler behavior, and dependencies are unchanged. This implements development-mode checks; it does not equate Rust debug builds with CPython's Py_DEBUG policy.

CPython basis

Pinned CPython source: unicode_check_encoding_errors, PyUnicode_FromEncodedObject, PyUnicode_Decode, and PyUnicode_AsEncodedString. Encoding lookup precedes error-handler lookup; validation failures are propagated before transformation-error notes are added. Codec lookup can invoke registered search functions, but validation does not call encode/decode or the selected error handler.

Validation

  • Scoped Cargo check, strict Clippy, and CLI build passed with an isolated target.
  • Four bounded direct interpreter runs passed: 97 observations in each of normal and development mode, with complete JSON equality against the pinned CPython reference in both modes. Covers empty/ASCII inputs, validation order, aliases, registered error names, and codec cache/search callbacks.
  • The unchanged canonical subprocess tests are reserved for hosted CI, not run locally. No startup/finalizer or concurrency probes were run locally; full-suite compatibility is not claimed.
  • Normal configured commit hooks passed for this change. Exact-head hosted CI is pending.

AI assistance

OpenAI Codex assisted with implementation, CPython source comparison, and validation. The model version was unavailable.

Match CPython preflight lookup order before text fast paths and empty decoding. Enable after core codec bootstrap and avoid finalization checks. Restore existing bytes and str development-mode checks through update_lib.

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

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[ ] test: cpython/Lib/test/test_bytes.py (TODO: 10)

dependencies:

dependent tests: (no tests depend on bytes)

[x] test: cpython/Lib/test/test_str.py (TODO: 1)
[ ] test: cpython/Lib/test/test_fstring.py (TODO: 1)
[x] test: cpython/Lib/test/test_string_literals.py

dependencies:

dependent tests: (no tests depend on str)

Legend:

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

@codspeed

codspeed Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:py315-dev-codec-preflight-20261030 (af8a6b1) with main (d24ca41)

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. ↩

Comment thread crates/vm/src/codecs.rs
}

pub(crate) fn finish_core_codec_bootstrap(&self) {
self.inner.write().core_codecs_ready = true;

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.

review this design again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CPython gates this check on interp->unicode.fs_codec.encoding, which becomes available before stdio initialization—not on general interpreter readiness (guard, initialization order). RustPython currently has no equivalent nullable filesystem-codec state. Its initialized/ready flags become true after stdio; import_bootstrap_complete also controls frozen-import fallback. Registry cache/search-path contents are not substitutes: they can be incomplete during bootstrap and later cleared by users, and a core-only embedding may have no search callbacks.

If we retain the before-stdio behavior, a separate interpreter-local completion marker is therefore the smallest available representation. The current transition occurs only after successful core codec registration, including core-only embeddings. This is a RustPython phase analogue, not identical filesystem-codec initialization, and post-startup test passes alone do not establish lifecycle equivalence.

A small clarification/simplification is possible: determine first whether either name actually requires lookup, and return immediately when both are builtin shortcuts. Only the remaining cases need to read the readiness marker. This preserves encoding-before-error-handler lookup and does not add state or change the bootstrap boundary. I would keep broader startup or synchronization changes out of this patch.

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