Skip to content

fix: handle VAR_POSITIONAL and kwargs precedence in _fast_bind cache#556

Merged
fgmacedo merged 1 commit intodevelopfrom
fix/signature-fast-bind
Feb 13, 2026
Merged

fix: handle VAR_POSITIONAL and kwargs precedence in _fast_bind cache#556
fgmacedo merged 1 commit intodevelopfrom
fix/signature-fast-bind

Conversation

@fgmacedo
Copy link
Owner

Summary

Fixes three bugs in the _fast_bind cached path introduced by #550:

  • VAR_POSITIONAL (*args): Was stored as raw args[i] instead of args[i:] tuple, causing TypeError: 'int' object is not iterable in BoundArguments.args
  • KEYWORD_ONLY after *args: Params after *args (e.g., def fn(*args, event, **kwargs)) were skipped entirely — the loop broke at VAR_POSITIONAL without processing remaining keyword-only params
  • POSITIONAL_OR_KEYWORD kwargs precedence: When a param name appears in both positional args and kwargs, _full_bind prefers kwargs, but _fast_bind always used the positional arg

These bugs only manifest when the _bind_cache (on a shared SignatureAdapter instance) is populated by one call shape and reused by another — e.g., across SCXML test cases that share callbacks via signature_cache.

Test plan

  • Added test_var_positional_collected_as_tuple — verifies *args collected as tuple on cache hit
  • Added test_keyword_only_after_var_positional — verifies KEYWORD_ONLY params after *args work
  • Added test_positional_or_keyword_prefers_kwargs_over_positional — verifies kwargs precedence
  • Added test_empty_var_positional — verifies empty *args edge case
  • Added test_named_params_before_var_positional — verifies named params before *args
  • Added test_kwargs_wins_with_var_positional_present — verifies kwargs precedence with *args
  • Full test suite passes (357 passed, 9 xfailed)

Fixes SCXML W3C test failures (test179, test527, test529, test562, test578) on the macedo/scxml branch CI.

The _fast_bind method had three bugs when replaying cached binding templates:

1. VAR_POSITIONAL (*args) params were stored as a single value (args[i])
   instead of a tuple (args[i:]), causing TypeError when BoundArguments.args
   tried to extend() a non-iterable value.

2. KEYWORD_ONLY params after *args were not processed at all — the loop
   would break at the VAR_POSITIONAL and skip remaining params.

3. POSITIONAL_OR_KEYWORD params that share a name with a kwarg key should
   prefer the kwargs value (matching _full_bind behavior), but _fast_bind
   always used the positional arg.

These bugs only manifested when the bind cache was shared across tests via
the module-level signature_cache (different callables with the same
signature sharing a SignatureAdapter instance).

Fixes issues observed in SCXML W3C tests (test179, test527, test529,
test562, test578) when run together with the bind cache from #550.
@sonarqubecloud
Copy link

@fgmacedo fgmacedo merged commit 37e6c1a into develop Feb 13, 2026
12 of 13 checks passed
@fgmacedo fgmacedo deleted the fix/signature-fast-bind branch February 13, 2026 11:48
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.

1 participant

Comments