Repository navigation
fix(python): multi-line header defaults, nested-class and package-reached dunders, lib/ import root - #4891
Conversation
…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
|
Warning Review limit reachedNext included review available in 3 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (10)
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. Comment |
There was a problem hiding this comment.
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
…ound-2-cmtps4 # Conflicts: # CHANGELOG.md
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P
…ound-2-cmtps4 # Conflicts: # CHANGELOG.md
EffortlessSteven
left a comment
There was a problem hiding this comment.
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
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| let changed = if multi_line_header_line { | ||
| declared_line_defaults(owner, new_line_text)? |
There was a problem hiding this comment.
🔴 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.
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") { |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
💡 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".
| 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)? |
There was a problem hiding this comment.
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 👍 / 👎.
| 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); |
There was a problem hiding this comment.
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 👍 / 👎.
Requested by Steven · project thread
Summary
Before:
defheader was creditedexposedwhenever 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.f(a=5)as binding a positional-onlya, althougha=5lands in**kw.Outer.Inner.__init__) never related to a test that buildsOuter.Inner(...).__get__behind a public decorator readno_static_path(cachetools 57d2e48). The project's suite detects the mutant of that line.lib/pkg/lost every relation to tests importingpkg.After:
weakly_exposedand names the call to add, one that omits the parameter.static_unknownwith thedynamic_dispatchlimit.lib/is an import root likesrc/.These are the four follow-ups #4533 left in the replay ledger.
How:
changed_default_overridden_paramstakes amulti_line_header_lineflag. The diff loop sets it from the cached per-ownermulti_line_def_header_span.header_param_line_defaultsreads 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.class_path, the full enclosing class path.qualified_nameis unchanged, so no output changes for other owners.test_may_reach_owner_classaccepts an import from the owner's module or a package above it.owner_module_pathsadds the path below a rootlib.Swarm / Source Boundary
ripr-swarmSource-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 falseno_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
Scope Classification
Non-goals:
cls(...)factories construct through receivers the scanner does not see, so they fail open;Support-tier Impact
Policy Impact
Proof
New tests:
multi_line_header_default_bound_by_every_call_is_not_exposedconstructor_default_fails_open_because_constructions_hide_behind_subclassesmulti_line_header_default_reads_only_declared_parameterspositional_only_default_is_not_bound_by_a_keyworddiff_mode_reads_a_default_added_inside_a_multi_line_header(production diff path)header_param_line_defaults_reads_defaults_on_one_header_linenested_class_dunder_relates_through_its_outer_classprivate_descriptor_dunder_reached_through_its_package_is_a_limita_root_lib_directory_is_an_import_rootNegative experiments, each run with one production clause removed and each test then fails:
class_path;libroot.OSS replays on the fe5d20f release binary (
ripr check --base C^); fd53468 only makes the default guard stricter about when it downgrades:_DescriptorBase.__get__lines 80, 84 and 85 moved from 3no_static_pathto 3static_unknown(dynamic_dispatch).Review
An independent adversarial review of fe5d20f found a false
weakly_exposed: the constructor path downgraded aWidget.__init__default when every visibleWidget(...)passedlabel, although the test also builtSmall(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 thelib/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_aliasbuilds anAttribute(...)that omitsalias_is_default, so the default is reached. The mutant survives because_transform_attrsoverwritesalias_is_defaulttoTruefor every field without an alias, which static evidence cannot see. That line staysexposed: the guard correctly sees an omitting call.Rollback
Revert the squash commit; no schema or output-contract changes.
Spec-Test-Code Traceability
crates/ripr/src/analysis/language/python/tests.rspython/no_behavior.rs,python/classify.rs,python.rs,python/related_tests.rs,python/owners_tests.rs,python/static_limits.rsStatic Language Check
killed,survived,untested,proven, andadequate.Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.Gates
cargo fmt --checkcargo xtask precommit🤖 Generated with Claude Code
https://claude.ai/code/session_01Np4sJkq1jfbMTLg3Uz7s5P