Skip to content

Commit afc0bf5

Browse files
committed
ISSUE-005: Include positional-only parameters in argument capture
- Fix `on_py_start` to include positional-only parameters by selecting `co_posonlyargcount + co_argcount` names from `co_varnames` for the positional slice. - Keep existing handling for `*args`, keyword-only, and `**kwargs` intact. - Rationale: `co_argcount` counts only pos-or-keyword parameters; omitting `co_posonlyargcount` dropped names before `/` (PEP 570). This patch ensures complete positional argument coverage and aligns with CPython ordering. - Validation: Python tests already cover this via `test_all_argument_kinds_recorded_on_py_start` which asserts presence of `p` from `def g(p, /, q, *args, r, **kwargs)`. The fix satisfies that check. Implementation notes: - No new public API; minimal, focused change in `runtime_tracer.rs`. - Followed repo rules to avoid unnecessary code and changes.
1 parent c53a408 commit afc0bf5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

codetracer-python-recorder/src/runtime_tracer.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ impl Tracer for RuntimeTracer {
158158

159159
// Argument names come from co_varnames in the order defined by CPython:
160160
// [positional (pos-only + pos-or-kw)] [+ varargs] [+ kw-only] [+ kwargs]
161-
let argcount = code.arg_count(py)? as usize; // includes pos-only + pos-or-kw
161+
// Note: `co_argcount` includes only pos-or-keyword parameters.
162+
// Positional-only parameters are reported separately via `co_posonlyargcount`.
163+
let argcount = code.arg_count(py)? as usize; // pos-or-keyword only
162164
let posonly: usize = code
163165
.as_bound(py)
164166
.getattr("co_posonlyargcount")?
@@ -177,7 +179,8 @@ impl Tracer for RuntimeTracer {
177179

178180
// 1) Positional parameters (pos-only + pos-or-kw)
179181
let mut idx = 0usize;
180-
let take_n = std::cmp::min(argcount, varnames.len());
182+
let total_positional = posonly.saturating_add(argcount);
183+
let take_n = std::cmp::min(total_positional, varnames.len());
181184
for name in varnames.iter().take(take_n) {
182185
match locals.get_item(name) {
183186
Ok(val) => {

issues.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ to preserve structure.
6363
Partially done
6464

6565
Implemented varargs (`*args`), keyword-only, and kwargs (`**kwargs`) capture.
66-
Positional-only parameters are read (`co_posonlyargcount`) but not yet included
67-
in the positional slice, so they are currently omitted. Follow-up: include
68-
`posonly + co_argcount` when selecting positional names.
66+
Positional-only parameters are now included in the positional slice via
67+
`co_posonlyargcount + co_argcount` (see ISSUE-005). Remaining gap: structured
68+
encoding for `*args`/`**kwargs` per Definition of Done (currently accepted as
69+
backend-dependent; tests allow `Raw`).
6970

7071
## ISSUE-005
7172
### Description
@@ -80,7 +81,11 @@ arguments (PEP 570). As a result, names before the `/` in a signature like
8081
- Tests add a function with positional-only parameters and assert their presence and correct encoding.
8182

8283
### Status
83-
Not started
84+
Done
85+
86+
Implemented by selecting positional names from `co_varnames` with
87+
`co_posonlyargcount + co_argcount`. Tests in `test_all_argument_kinds_recorded_on_py_start`
88+
assert presence of the positional-only parameter `p` and pass.
8489

8590
## ISSUE-003
8691
### Description

0 commit comments

Comments
 (0)