Skip to content

Allow explicit insertion of absent canonical test methods - #9388

Closed
youknowdot wants to merge 2 commits into
RustPython:mainfrom
youknowdot:cpython-315-update-lib-insert-test
Closed

youknowdot wants to merge 2 commits into
RustPython:mainfrom
youknowdot:cpython-315-update-lib-insert-test

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in scripts/update_lib copy-test --insert-before ClassName.anchor mode to insert a canonical class method that is absent from the destination. The existing replacement mode and its behavior remain unchanged.

This closes a selective-updater gap without refreshing an entire test module or hand-editing Lib: copy-test previously required the method to exist on both sides, while migrate --functions handles module-level functions rather than class methods. This PR does not migrate any actual Lib file or canonical test.

The insertion mode deliberately requires:

  • An unambiguous, direct, unguarded method immediately preceding the canonical anchor, in the same class.
  • An unchanged anchor and class header, matching indentation, and no conflicting destination binding or scope declarations.
  • Blank definition boundaries, so surrounding comments are not silently omitted or attached to another definition.
  • Hash-pinned UTF-8 inputs with LF endings and a final newline; verbatim copying of the selected decorated definition and preservation of all destination bytes outside the insertion.

Binding checks follow class execution scope: unrelated nested method, lambda, class, and comprehension-local names do not block insertion. Definition headers and class control-flow bindings remain checked.

The existing pre-write destination byte recheck rejects stale inputs; it is not an atomic concurrent-write transaction. The tool copies no imports or helpers and does not establish semantic dependency closure or RustPython support. Those remain part of each subsequent migration's review. Conservative checks intentionally reject some otherwise harmless cases rather than guessing.

Validation

  • All 24 updater tooling tests in update_lib.tests.test_copy_test passed: 10 preserved replacement tests, 10 original insertion tests, and four lexical-scope regressions.
  • The exact module ran under an isolated, bounded host Python 3.12 harness (30-second/512-MiB limits), with synthetic text and owned temporary files only. No fixture imports, subprocess/network operations, or actual Lib access; source/input hashes unchanged and process/temp cleanup verified.
  • Normal commit hooks passed: merge-conflict check, Ruff formatting, and Ruff import checks.

No Rust build, RustPython runtime workload, actual canonical test, or fixture was executed. The synthetic source is parsed rather than executed.

Base: 30b8239d1b4b49c001adadad2bf19c1d4ba77381.
Validated tree: 2dab7e663962e81e979685add619cb0498bb94c5.

AI-assisted implementation and review; assistance is disclosed in the commit trailer.

Add a hash-pinned copy-test --insert-before mode for a missing method
beside an unchanged canonical anchor. Preserve default replacement and
all destination bytes outside the selected insertion; reject ambiguous
scopes, bindings, boundary comments, or changed anchors conservatively.

Validate the updater with 20 bounded synthetic-text tooling tests and
normal affected hooks. No Lib files or actual canonical tests are changed;
no RustPython runtime, fixtures, or Rust builds are executed.

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

coderabbitai Bot commented Oct 26, 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.

Inspect class bindings without treating unrelated nested method, lambda,
class, or comprehension-local names as class bindings. Preserve definition
header expressions and class control-flow checks, including source and
destination scope declarations and target/anchor protections.

Preserve all 20 original updater tests and add four synthetic-text scope
regressions. All 24 tooling tests passed under the bounded isolated gate;
no actual Lib migration, canonical tests, or RustPython runtime executed.

Assisted-by: OpenAI Codex:model version unavailable

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

dup of #9363. I also didn't get what's the purpose of this patch yet. we usually update the entire test, not single function.

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