Backtestspydanticrun-20260929-204949#13771
validate_call cannot call a function with a keyword parameter named self
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches apply the identical, correct root-cause fix: making `self` positional-only in `__call__` (`self, /`). The tie-breaker is test quality. Patch A's test mirrors the issue exactly (`def f(*, self: int)` keyword-only) and asserts three behaviors: valid int passthrough, coercion of '2' to 2, and a ValidationError on a bad value—confirming validation still runs after the collision is removed. Patch B's test uses `def func(self: int)` (positional-or-keyword) and only asserts `func(self=1) == 1`, covering neither coercion nor the failure path. Both tests would fail pre-fix and pass post-fix, but A's is more faithful to the reported case and more thorough. Scope and craft are otherwise equal.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
3m 14s14 turns
Wall-clock time in the container
Full test suite
No new failures
12,498 passed · 509 skipped · 13,007 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
16vs 12 merged
Changed lines, ours vs merged
The issue
View on GitHubInitial Checks
- I confirm that I'm using Pydantic V2
Description
ValidateCallWrapper.__call__ is declared as def __call__(self, *args, **kwargs), so the instance is bound to the name self. A decorated function with a keyword parameter literally named self can then never be called with it: f(self=1) raises TypeError: ValidateCallWrapper.__call__() got multiple values for argument 'self' before validation runs. The wrapped function itself is fine with that name; it is only the wrapper's signature that collides. Same in 2.12.5, 2.13.5 and pydantic/_internal/_validate_call.py on main.
Making self positional-only in __call__ (def __call__(self, /, *args, **kwargs)) removes the collision without changing anything else. Can send the PR.
Example Code
import pydantic.version
from pydantic import validate_call
@validate_call
def f(*, self: int) -> int:
return self
try:
print("f(self=1) ->", f(self=1))
except TypeError as e:
print("f(self=1) -> TypeError:", e)
print(pydantic.version.version_info())
f(self=1) -> TypeError: ValidateCallWrapper.__call__() got multiple values for argument 'self'
Python, Pydantic & OS Version
pydantic version: 2.13.5
pydantic-core version: 2.46.5
pydantic-core build: profile=release pgo=false
python version: 3.12.13 (main, May 10 2026, 19:20:41) [Clang 22.1.3 ]
platform: macOS-26.5.2-arm64-arm-64bit
related packages: typing_extensions-4.16.0
commit: unknownThe two patches
pydantic/_internal/_validate_call.pyindex 1559d070..10f12cc8 100644@@ -130,7 +130,7 @@ class ValidateCallWrapper: self.__pydantic_complete__ = True - def __call__(self, *args: Any, **kwargs: Any) -> Any:+ def __call__(self, /, *args: Any, **kwargs: Any) -> Any: if not self.__pydantic_complete__: self._create_validators() tests/test_validate_call.pyindex 3d86e451..bbe1fb1a 100644@@ -515,6 +515,20 @@ def test_args_name(): ] +def test_self_keyword_argument():+ """https://github.com/pydantic/pydantic/issues/13773"""++ @validate_call+ def f(*, self: int) -> int:+ return self++ assert f(self=1) == 1+ assert f(self='2') == 2++ with pytest.raises(ValidationError):+ f(self='not an int')++ def test_async(): @validate_call async def foo(a, b):
pydantic/_internal/_validate_call.pyindex 1559d0705..10f12cc80 100644@@ -130,7 +130,7 @@ class ValidateCallWrapper: self.__pydantic_complete__ = True - def __call__(self, *args: Any, **kwargs: Any) -> Any:+ def __call__(self, /, *args: Any, **kwargs: Any) -> Any: if not self.__pydantic_complete__: self._create_validators() tests/test_validate_call.pyindex 3d86e4517..6d97b1e80 100644@@ -1339,3 +1339,13 @@ def test_pickle_validate_call_with_basemodel() -> None: assert unpickled == {1: _PickleTestModel(number=1.0)} assert unpickled[1].number == 1.0+++def test_validate_call_self_parameter() -> None:+ """https://github.com/pydantic/pydantic/issues/13771"""++ @validate_call+ def func(self: int):+ return self++ assert func(self=1) == 1
What the agent reported
The review confirms the fix is correct, minimal, and complete. Done.
Summary
What was wrong: In pydantic/_internal/_validate_call.py, ValidateCallWrapper.__call__ was declared def __call__(self, *args, **kwargs). The instance binds to the name self, so any @validate_call-decorated function with a keyword parameter literally named self could never be called with it — f(self=1) raised TypeError: ValidateCallWrapper.__call__() got multiple values for argument 'self' before validation ever ran.
What I changed:
pydantic/_internal/_validate_call.py:133— madeselfpositional-only:def __call__(self, /, *args, **kwargs). Now a user-suppliedself=...flows into**kwargsinstead of colliding with the bound instance. Single-character change, exactly as the report proposed.tests/test_validate_call.py— addedtest_self_keyword_argument(issue #13773) assertingf(self=1) == 1, coercionf(self='2') == 2, andValidationErroron a non-coercible value.
Test evidence:
- Reproduced the exact reported
TypeErrorbefore the fix (via.venv/bin/python). - The new regression test failed before the production change with the exact reported
TypeError, and passes after. - Gate:
./bt-test tests/test_validate_call.py→ 65 passed (exit 0), including the new test; no previously passing test regressed. - Reviewer confirmed the diff matches the report,
__call__is the only affected collision site (the module-level wrapper functions have noself/clsparam and just forward kwargs), and nothing unrelated changed.
Requirements disposition:
- Fix
validate_callso a function with a keyword param namedselfis callable — implemented, with a regression test seen failing before and passing after. - Report's proposed approach (
def __call__(self, /, *args, **kwargs)) — implemented exactly; verified no other collision sites in the file require the same change (evidence: reviewer's read ofupdate_wrapper_attributesand all other methods).
All changes are left uncommitted in the working tree.