Skip to content

fix: record positional optional params and **kwargs correctly - #389

Merged
dividedmind merged 1 commit into
masterfrom
fix/positional-optional-params
Nov 10, 2026
Merged

dividedmind merged 1 commit into
masterfrom
fix/positional-optional-params

Conversation

@dividedmind

Copy link
Copy Markdown
Contributor

Parameters with a default were only looked up in kwargs, so when passed positionally they were recorded as their default value, and the positional values spilled over into *args instead. E.g. for f(self, a, b=None) called as f('A', 'B'), b was recorded as None.

**kwargs was recorded as the full keyword argument dict, including arguments bound to named parameters. It now only contains the ones Python would actually put there. In particular, keyword arguments named like positional-only parameters now go to **kwargs rather than being recorded as the value of the positional-only parameter.

Assisted-by: Claude:claude-opus-5-5

@dividedmind
dividedmind requested review from kgilpin and a balanced review from Copilot November 9, 2026 18:23
@dividedmind dividedmind self-assigned this Nov 9, 2026

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the Python argument-recording changes.

No open issues 🎉

What changed in this PR

This PR corrects how AppMap records Python function arguments, aligning recorded parameter values with Python’s argument binding behavior.

Changes:

  • Record optional parameters passed positionally without incorrectly including them in *args.
  • Exclude named keyword parameters from recorded **kwargs, while preserving keywords that match positional-only parameter names.
  • Add regression tests for mixed parameter kinds, defaults, and positional-only name collisions.
File Description
_appmap/​test/​test_params.py Adds regression tests for positional defaults and keyword argument binding.
_appmap/​test/​data/​params.py Adds mixed-parameter and positional-only test fixtures.
_appmap/​event.py Tracks positional-only parameters and corrects parameter value selection and **kwargs filtering.

Review effort: Balanced

Parameters with a default were only looked up in kwargs, so when passed
positionally they were recorded as their default value, and the
positional values spilled over into *args instead. E.g. for
f(self, a, b=None) called as f('A', 'B'), b was recorded as None.

**kwargs was recorded as the full keyword argument dict, including
arguments bound to named parameters. It now only contains the ones
Python would actually put there. In particular, keyword arguments
named like positional-only parameters now go to **kwargs rather than
being recorded as the value of the positional-only parameter.

Assisted-by: Claude:claude-opus-5-5
@dividedmind
dividedmind force-pushed the fix/positional-optional-params branch from a4952a6 to 4082a7c Compare November 10, 2026 17:24
@dividedmind
dividedmind merged commit d92c301 into master Nov 10, 2026
7 checks passed
@dividedmind
dividedmind deleted the fix/positional-optional-params branch November 10, 2026 19:06
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