Backtestspydanticrun-20261022-024030#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 B = our agent, Patch A = the merged fix.
Both patches make the identical core change: `ValidateCallWrapper.__call__(self, /, *args, **kwargs)`, which is exactly the fix the issue proposes and resolves the root cause (the wrapper's bound `self` name colliding with a keyword argument). The independent tests confirm both pass all five scenarios, so correctness is equal on the reported issue. The difference is in tests and craft. Patch A adds a single minimal test with a positional-or-keyword `self` called by keyword; it would fail on base and pass after, but it does not cover the issue's literal example (keyword-only `self`), does not check that validation actually runs on the `self` argument, and does not cover `**kwargs` or async paths. Patch B's test exercises keyword-only `self` (the issue's exact case), positional-or-keyword passed both ways, `**kwargs` receiving `self`, the ValidationError `loc == ('self',)` showing validation now reaches the argument, and the async wrapper path. Patch B also applies the same positional-only fix to the deprecated `ValidatedFunction.init_model_instance`/`call` in `pydantic/deprecated/decorator.py`, which has the identical collision, and adds a matching test. That is adjacent work and earns no credit on its own, but it is the same root cause, is a one-token change per method, and adds no risk, so it does not count against B. With equal correctness and scope risk, B's substantially stronger test coverage decides it.
Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.
Solve
3m 31s
Wall-clock time in the container
Full test suite
No new failures
135 passed · 0 skipped · 135 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
54vs 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() pydantic/deprecated/decorator.pyindex b8dc224f..7c2e17f8 100644@@ -142,11 +142,11 @@ class ValidatedFunction: self.create_model(fields, takes_args, takes_kwargs, config) - def init_model_instance(self, *args: Any, **kwargs: Any) -> BaseModel:+ def init_model_instance(self, /, *args: Any, **kwargs: Any) -> BaseModel: values = self.build_values(args, kwargs) return self.model(**values) - def call(self, *args: Any, **kwargs: Any) -> Any:+ def call(self, /, *args: Any, **kwargs: Any) -> Any: m = self.init_model_instance(*args, **kwargs) return self.execute(m) tests/test_deprecated_validate_arguments.pyindex 4fa70b37..fbc05c14 100644@@ -185,6 +185,21 @@ def test_args_name(): foo(1, 2, 3) +def test_self_name():+ """A parameter named `self` must not collide with `ValidatedFunction`'s own `self`."""++ @validate_arguments+ def foo(self: int, *, other: int = 0):+ return f'self={self!r}, other={other!r}'++ assert foo(self='1', other='2') == 'self=1, other=2'+ assert foo('3') == 'self=3, other=0'+ assert foo.validate(self='4').self == 4++ with pytest.raises(ValidationError):+ foo(self='x')++ def test_v_args(): with pytest.raises( PydanticUserError,tests/test_validate_call.pyindex 3d86e451..65ecaed9 100644@@ -515,6 +515,39 @@ def test_args_name(): ] +def test_self_name() -> None:+ """A parameter named `self` must not collide with the wrapper's own `self`."""++ @validate_call+ def kw_only(*, self: int) -> int:+ return self++ assert kw_only(self='1') == 1++ @validate_call+ def pos_or_kw(self: int, other: int = 0) -> tuple[int, int]:+ return self, other++ assert pos_or_kw(self='1', other='2') == (1, 2)+ assert pos_or_kw('3') == (3, 0)++ @validate_call+ def var_kwargs(**kwargs: int) -> dict[str, int]:+ return kwargs++ assert var_kwargs(self='1') == {'self': 1}++ with pytest.raises(ValidationError) as exc_info:+ kw_only(self='x')+ assert exc_info.value.errors(include_url=False)[0]['loc'] == ('self',)++ @validate_call+ async def async_kw_only(*, self: int) -> int:+ return self++ assert asyncio.run(async_kw_only(self='4')) == 4++ 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