Skip to content

fix(python): multi-line header defaults, nested-class and package-reached dunders, lib/ import root - #4891

Merged
EffortlessSteven merged 10 commits into
mainfrom
claude/oss-accuracy-round-2-cmtps4
Sep 29, 2026
Merged

EffortlessSteven merged 10 commits into
mainfrom
claude/oss-accuracy-round-2-cmtps4

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Requested by Steven · project thread

Summary

Before:

  • A parameter default on its own line inside a multi-line def header was credited exposed whenever a strong test reached the owner. This held even when every call passed that parameter, because the changed-default guard read only one-line headers.
  • The one-line guard counted f(a=5) as binding a positional-only a, although a=5 lands in **kw.
  • A dunder of a nested class (Outer.Inner.__init__) never related to a test that builds Outer.Inner(...).
  • A private descriptor's __get__ behind a public decorator read no_static_path (cachetools 57d2e48). The project's suite detects the mutant of that line.
  • An owner under lib/pkg/ lost every relation to tests importing pkg.

After:

  • The guard reads the defaults on a multi-line header line, bound to the owner's declared parameters. When every strong related call passes the parameter, the line reads weakly_exposed and names the call to add, one that omits the parameter.
  • A keyword never binds a positional-only parameter.
  • Nested-class dunders relate through the outer class.
  • A dunder with no related test whose tests import anything from its package reads static_unknown with the dynamic_dispatch limit.
  • A root lib/ is an import root like src/.

These are the four follow-ups #4533 left in the replay ledger.

How:

  • changed_default_overridden_params takes a multi_line_header_line flag. The diff loop sets it from the cached per-owner multi_line_def_header_span.
  • header_param_line_defaults reads the names on that line, and each must be a declared parameter of the owner with a default. That gives it its real position and binding kind, and rejects a keyword inside a nested default call.
  • Methods still fail open, constructors included.
  • Method owners carry class_path, the full enclosing class path. qualified_name is unchanged, so no output changes for other owners.
  • test_may_reach_owner_class accepts an import from the owner's module or a package above it.
  • owner_module_paths adds the path below a root lib.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Spec: RIPR-SPEC-0028 (Python preview static facts), relation and default rules updated.
Governing issue or accepted claim: follow-ups of #4533 (replay ledger accuracy/2026-09-28-oss-replay-ledger.md, P3, P6, cachetools 57d2e48, lib/ layout).
Acceptance delta (one sentence): Python multi-line header defaults, nested-class dunders, package-reached dunders and lib/ owners no longer produce a false exposed, a missing relation or a false no_static_path.

Candidate Relationships

Candidate branch: claude/oss-accuracy-round-2-cmtps4, restarted from main after #4533 merged. Searched open PRs: #4612 (test-pattern accuracy) and #4845 (same-class method reach) touch other claims; no equivalent PR.

Scope

  • Python preview adapter: changed-default guard, dunder class resolution, dunder dispatch limit, import roots.

Scope Classification

  • One production behavior

Non-goals:

  • single-line headers that add a new parameter (still need a paired pure value change);
  • methods and constructors: subclasses and cls(...) factories construct through receivers the scanner does not see, so they fail open;
  • values that production code overwrites after construction (see Claim Boundary).

Support-tier Impact

  • none

Policy Impact

  • none

Proof

cargo test -p ripr --lib analysis   # 3130 passed (merged head 79382e9)
cargo xtask precommit               # rc=0
cargo xtask goldens check           # rc=0

New tests:

  • multi_line_header_default_bound_by_every_call_is_not_exposed
  • constructor_default_fails_open_because_constructions_hide_behind_subclasses
  • multi_line_header_default_reads_only_declared_parameters
  • positional_only_default_is_not_bound_by_a_keyword
  • diff_mode_reads_a_default_added_inside_a_multi_line_header (production diff path)
  • header_param_line_defaults_reads_defaults_on_one_header_line
  • nested_class_dunder_relates_through_its_outer_class
  • private_descriptor_dunder_reached_through_its_package_is_a_limit
  • a_root_lib_directory_is_an_import_root

Negative experiments, each run with one production clause removed and each test then fails:

  • the declared-parameter binding;
  • the positional-only rule (multi-line and one-line);
  • the multi-line branch of the guard;
  • the diff-loop flag;
  • class_path;
  • the package-import clause;
  • the lib root.

OSS replays on the fe5d20f release binary (ripr check --base C^); fd53468 only makes the default guard stricter about when it downgrades:

  • cachetools 57d2e48 _DescriptorBase.__get__ lines 80, 84 and 85 moved from 3 no_static_path to 3 static_unknown (dynamic_dispatch).
  • attrs 862696a, packaging 55cbf1b and fe18f13, and cachetools 39b31bc and c0fdf6a keep identical classifications on every line.

Review

An independent adversarial review of fe5d20f found a false weakly_exposed: the constructor path downgraded a Widget.__init__ default when every visible Widget(...) passed label, although the test also built Small(Widget) and reached the default. It also found two misreads of header lines: a keyword inside a nested default call, and a positional-only parameter bound by keyword.

All three are fixed in fd53468, and each has a test that fails with the old code. The same review found no regression from class_path, the package clause or the lib/ root. Gemini reviewed fe5d20f with no findings; CodeRabbit is rate-limited.

Claim Boundary

May claim: the four listed shapes no longer produce the wrong class.

Must not claim that attrs 862696a line 2513 is fixed. The ledger's P3 diagnosis was wrong. test_hook_new_field_without_alias builds an Attribute(...) that omits alias_is_default, so the default is reached. The mutant survives because _transform_attrs overwrites alias_is_default to True for every field without an alias, which static evidence cannot see. That line stays exposed: the guard correctly sees an omitting call.

Rollback

Revert the squash commit; no schema or output-contract changes.

Spec-Test-Code Traceability

  • Spec: RIPR-SPEC-0028
  • Tests: crates/ripr/src/analysis/language/python/tests.rs
  • Code: python/no_behavior.rs, python/classify.rs, python.rs, python/related_tests.rs, python/owners_tests.rs, python/static_limits.rs
  • Golden outputs: unchanged

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.

Gates

  • cargo fmt --check
  • cargo xtask precommit

🤖 Generated with Claude Code

https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P

…nstructors

The changed-default guard read only one-line def headers and skipped every
method. A default on its own line inside a multi-line header, or on a
constructor dunder, was credited exposed even when every strong related
call passed that parameter. The guard now reads the defaults on a
multi-line header line and finds constructor calls through the class name,
module member or import alias. Positional constructor arguments never count
as binding, so an unresolved shape still fails open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
A dunder of a nested class (Outer.Inner.__init__) resolved its class as the
innermost name only, so a test that builds Outer.Inner(...) from an imported
Outer never related. Method owners now carry their full enclosing class path
(class_path); qualified_name is unchanged. The dunder relation binds the
outermost class through the owner-module import rules and then requires the
nested member path.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
…static_path

cachetools 57d2e48: the private _DescriptorBase.__get__ runs whenever a test
reads a @cachedmethod attribute, and the suite killed the mutant of the
changed line, but no test names the private base, so ripr said
no_static_path. A dunder owner with no related test whose tests import
anything from its module or a package above it now reads static_unknown with
the dynamic_dispatch limit. A same-named package elsewhere does not count.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
After #4533 bound dunder relations to the owner's own module paths, an owner
under lib/pkg/cache.py matched only lib.pkg.cache, so tests importing
pkg.cache lost their relation. A lib/ directory at the repository root is
now an import root like src/. A nested lib/ stays a package segment.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
…-reach and lib-root fixes

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
…comment

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 4ee1d1e7-fa30-4133-ad52-0a1fd5fe2812

📥 Commits

Reviewing files that changed from the base of the PR and between 188eced and b11573b.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/classify.rs
  • crates/ripr/src/analysis/language/python/no_behavior.rs
  • crates/ripr/src/analysis/language/python/owners_tests.rs
  • crates/ripr/src/analysis/language/python/python_tests.rs
  • crates/ripr/src/analysis/language/python/related_tests.rs
  • crates/ripr/src/analysis/language/python/static_limits.rs
  • crates/ripr/src/analysis/language/python/tests.rs
  • docs/specs/RIPR-SPEC-0028-python-preview-static-facts.md

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the Python analysis adapter in ripr by improving the accuracy of exposure classification for parameter defaults, nested classes, and dunder methods. Specifically, it correctly handles parameter defaults defined on individual lines within multi-line def headers and constructor methods (__init__/__new__), ensuring they are classified as weakly_exposed when all related calls explicitly pass the parameter. It also adds support for resolving nested class dunder methods (e.g., Outer.Inner.__init__), improves the detection of dunder methods reached via package imports (classifying them as static_unknown with a dynamic_dispatch limit), and recognizes a root lib/ directory as an import root. Corresponding unit tests and specification documentation have been updated. I have no feedback to provide as there are no review comments.

…ults to declared parameters

Review of this PR found a false weakly_exposed: a constructor default was
downgraded when every visible Widget(...) passed the parameter, although a
test also built a subclass (or used a cls(...) factory) that reaches the
default. Methods, constructors included, now fail open as before.

A multi-line header line's names must be declared parameters of the owner
with a default, which rejects a keyword inside a nested default call and
gives each parameter its real position. A keyword never binds a
positional-only parameter, in the one-line guard too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Exact-head review of b11573b: REVIEW_READY.

Inspected: the full diff (guard, header-line reader, diff-loop flag, class_path, package clause, lib root), consumers of qualified_name (unchanged), test stimulus and oracle for each new test, and the negative experiments listed in the body. The three adversarial-review findings on fe5d20f (constructor false weakly_exposed, nested-default misread, posonly keyword binding) are fixed in fd53468 with failing-before tests. Commits after fd53468 are main merges plus class_path on new main literals.

Evidence: CI green on b11573b, including Rust gates, feature lane, ub-review, cargo-deny and source-of-truth; no conflict with main. Local: 3165 analysis tests and cargo xtask precommit rc=0.

Missing review recorded: Gemini clean on fe5d20f (not re-run on this head); CodeRabbit rate-limited; droid-review did not report. All three are missing review, not clean review.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review September 29, 2026 10:01
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@EffortlessSteven
EffortlessSteven merged commit 2e677e3 into main Sep 29, 2026
25 of 27 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 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 ✅ Completed 2026-09-29T10:05:15.854967Z b11573b 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.

@EffortlessSteven
EffortlessSteven deleted the claude/oss-accuracy-round-2-cmtps4 branch September 29, 2026 10:01

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment on lines +795 to +796
let changed = if multi_line_header_line {
declared_line_defaults(owner, new_line_text)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Changed default falsely reads exposed

When one of several defaults changes on a header line, declared_line_defaults includes unchanged defaults. An omitting call for an unchanged default clears the guard, so an explicitly overridden changed default reads exposed.

Learn more

The multi-line branch uses every default declared on the new line rather than comparing the old and new parameter lines. The guard returns no override as soon as a strong call omits any member of that list, even when the omitted member did not change. A strong oracle can then credit an unexercised changed default as exposed.

Example: Change def f(\n a=1, b=2,\n): to def f(\n a=1, b=3,\n):. A test asserting f(b=2) omits a but binds b; the changed b default never runs, yet the gate sees omitted a and allows exposed.

Recommended fix: For paired multi-line header lines, compare the old and new declarations and pass only defaults whose values changed to the binding check. Preserve conservative behavior for unpaired lines and unsupported shapes, and add a test with two defaults on one line where only one changes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

// `src/` is a layout root at any depth (`packages/x/src/pkg`); `lib/`
// only at the repository root, since a nested `lib` is usually a
// package of its own (`pkg/lib/util.py` is `pkg.lib.util`).
if *part == "src" || (idx == 0 && *part == "lib") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Root lib imports credit the wrong module

When lib/pkg/util.py and pkg/util.py coexist, owner_module_paths gives both owners pkg.util. The ambiguity pass tracks only src, so tests of one owner can expose the other.

Learn more

The module identity checker accepts the newly added short path below root lib/. The ambiguity pass records duplicate short paths only when they arise below src/. Two owners can therefore accept the same import as identity evidence, and a strong test of one function can classify a different function as exposed.

Example: A checkout has lib/pkg/util.py and pkg/util.py, each defining price. A test imports price with from pkg.util import price and asserts its result. The lib owner receives the same identity match as the actual pkg/util.py owner.

Recommended fix: Extend src_layout_module_names and apply_src_module_ambiguity to account for short paths created by root lib/, and resolve duplicate imports conservatively when the test's project context cannot distinguish the modules. Add an owner-identity test with both files and an assertion against only one.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b11573bc7a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +795 to +798
let changed = if multi_line_header_line {
declared_line_defaults(owner, new_line_text)?
} else {
changed_default_value_params(old_line_text?, new_line_text)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Compare only the defaults that actually changed

Failure mode: On a paired multi-line header edit such as a=1, b=2, to a=1, b=3,, declared_line_defaults treats both defaults as changed. A strong test calling f(b=4) omits unchanged a, so the loop concludes that a changed default is exercised and can incorrectly retain exposed, even though the changed b default is always overridden. Fix direction: for paired lines, compare the old and new parameter segments and retain only names whose default values changed; reserve all declared defaults for genuinely new lines. Validation: add this two-default case to the Python analysis tests and run cargo test -p ripr --lib multi_line_header_default. Confidence: High.

AGENTS.md reference: AGENTS.md:L228-L232

Useful? React with 👍 / 👎.

Comment on lines +809 to 812
if *part == "src" || (idx == 0 && *part == "lib") {
let below = parts.get(idx + 1..).unwrap_or_default().join(".");
if !below.is_empty() && !paths.contains(&below) {
paths.push(below);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include root lib aliases in ambiguity tracking

Failure mode: Adding pkg.cache as an alias for lib/pkg/cache.py bypasses the existing ambiguity protection because src_layout_module_names still registers only paths below src. In a workspace that also contains plugins/x/src/pkg/cache.py, a test under that rival project importing pkg.cache can therefore relate to the root-lib owner and falsely promote evidence from the wrong module. Fix direction: register root lib aliases and their project roots in the same ambiguity map, then add a lib/nested-src rival regression test. Validation: run the focused Python related-test suite. Confidence: High.

AGENTS.md reference: AGENTS.md:L233-L236

Useful? React with 👍 / 👎.

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