Backtestspydanticrun-20260923-170312#13771

Issue #13771 Merged fix PR # Run 23 Sep 2026 · run-20260923-170312 pydantic/pydantic

validate_call cannot call a function with a keyword parameter named self

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

The source fix is byte-for-byte identical in both patches (adding `/` to make `self` positional-only in `ValidateCallWrapper.__call__`), so correctness and scope are equal — both resolve the root cause cleanly and minimally. The decision turns on test quality. Patch A reproduces the issue's exact scenario, a keyword-only parameter (`def f(*, self: int)`), and adds a second assertion `f(self='1') == 1` proving validation/coercion still runs after the fix, not merely that the name passes through. Patch B uses a positional-or-keyword parameter (`def func(self: int)`) and only asserts identity passthrough (`func(self=1) == 1`); it does verify the bug (the wrapper's bound `self` still collides via kwargs), and it adds a helpful issue-link docstring, but it exercises a weaker case and does not confirm validation behavior. Patch A's test is both a closer match to the report and more thorough, giving it the edge on criterion 2 while all else is 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

10m 12s8 turns

Wall-clock time in the container

Full test suite

No new failures

6,674 passed · 373 skipped · 7,047 total

Contamination audit

Unknown

See the audit notes for this run

Patch size

11vs 12 merged

Changed lines, ours vs merged

Initial 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: unknown

The two patches

Our patch+10 −1
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..4bf0f9b3 100644@@ -259,6 +259,15 @@ def test_kwargs():     ]  +def test_kwarg_named_self():+    @validate_call+    def f(*, self: int) -> int:+        return self++    assert f(self=1) == 1+    assert f(self='1') == 1++ def test_untyped():     @validate_call     def foo(a, b, c='x', *, d='y'): 
Merged fix · PR #+11 −1
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 fix is complete and verified.

Summary

What was wrong: ValidateCallWrapper.__call__ was declared as def __call__(self, *args, **kwargs), binding the wrapper instance to the name self. A @validate_call-decorated function with a keyword-only 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. The wrapped function itself is fine with that name; only the wrapper's signature collided.

What I changed:

  • pydantic/_internal/_validate_call.py (line 133): made self positional-only — def __call__(self, /, *args: Any, **kwargs: Any) -> Any:. Now self=... flows through **kwargs to the wrapped function instead of colliding. The second wrapping layer (wrapper_function) already used only *args, **kwargs, so no other change was needed.
  • tests/test_validate_call.py: added regression test test_kwarg_named_self decorating def f(*, self: int) and asserting f(self=1) == 1 plus f(self='1') == 1 (coercion).

Test evidence:

  • Before the fix, the new test failed with the exact reported TypeError at _validate_call.py:40.
  • After the fix, the full tests/test_validate_call.py suite passed: 65 passed (including the new test; all previously-passing tests still green).
  • Reviewer confirmed the diff is minimal and scoped to exactly the reported problem, with no unrelated or scratch-file changes.

Requirements disposition:

  1. Fix validate_call so a keyword parameter named self is callable (report's proposed self, / approach) — implemented, with passing regression test and full-suite gate.

Changes are left uncommitted in the working tree.