Backtestspydanticrun-20260930-144322#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 make the identical source change, making `self` positional-only in `ValidateCallWrapper.__call__`. That fixes the root cause and matches what the issue proposed, so they are equal on correctness and scope. The difference is in the tests. Both tests fail before the change and pass after it. Patch A reproduces the issue's exact keyword-only example (`def f(*, self: int)`). It also checks that validation still happens on the `self` parameter: `'2'` is coerced to `2`, and `'x'` raises `ValidationError`. That shows the argument reaches the validator and is not just passed through. Patch B uses a positional-or-keyword `self` and makes one happy-path assertion that does not exercise validation. Its docstring is also a leftover `<link>` placeholder, which is a minor craft issue. Patch A's test is placed among related parameter-kind tests, while Patch B's is appended at the end of the file. Overall, Patch A has the stronger and more faithful test.
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
1m 17s8 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
14vs 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..1dbfee7e 100644@@ -1008,6 +1008,18 @@ def f(a: int, /, **kwargs): assert module.f(1, a=2) == (1, {'a': 2}) +def test_keyword_parameter_named_self() -> None:+ @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='x')++ def test_model_as_arg() -> None: class Model1(TypedDict): x: int
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
Fixed: a @validate_call function with a keyword parameter named self can now be called with it. The regression test failed before the change, and it and the rest of tests/test_validate_call.py and tests/test_decorators.py pass after it (96 passed).
Cause: ValidateCallWrapper.__call__ in pydantic/_internal/_validate_call.py was declared as def __call__(self, *args, **kwargs). The decorator returns the bound method, so a call like f(self=1) gave the method a second value for its own self. Python raised TypeError: ... got multiple values for argument 'self' before validation ever ran.
Change (pydantic/_internal/_validate_call.py:133): made self positional-only, as the report suggested:
def __call__(self, /, *args: Any, **kwargs: Any) -> Any:
A keyword self=... now ends up in **kwargs and gets validated like any other argument. Nothing else in the method changed.
Test: I added test_keyword_parameter_named_self to tests/test_validate_call.py, right after test_positional_and_keyword_with_same_name. It uses the report's function (def f(*, self: int)) and checks three things:
f(self=1) == 1f(self='2') == 2, so the value is still being validated and convertedf(self='x')raisesValidationError
Test evidence:
- Before the fix: the new test failed with
TypeError: ValidateCallWrapper.__call__() got multiple values for argument 'self', which reproduces the report. - After the fix:
./bt-test tests/test_validate_call.py tests/test_decorators.pygave 96 passed, including the new test.
Blast radius: the only difference is that self can no longer be passed to __call__ by keyword. Only pydantic calls __call__, and binding the method always supplies self by position, so nothing that worked before is affected. The / syntax needs Python 3.8 or later, which pydantic already requires. The reviewer also checked the other wrappers in the call path: wrapper_function (sync and async) takes only *args, **kwargs, so it has no similar name clash.
Requirements:
f(self=1)should work instead of raisingTypeError: done; the new test covers it.- Use the suggested fix,
def __call__(self, /, *args, **kwargs): done exactly as written. The change is one line and only two files changed (checked withgit status). - "Without changing anything else": existing tests pass unchanged, and the reviewer found no other wrapper with the same problem.
- "Same on main": confirmed; main had the same signature before this edit.
The changes are uncommitted in the working tree, and I left no scratch files.