Skip to content

validate_arguments allows overriding positional argument with kwarg #2249

@antdking

Description

@antdking

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7.3
            pydantic compiled: True
                 install path: /home/anthony/.local/share/virtualenvs/project-4BYEWHa2/lib/python3.8/site-packages/pydantic
               python version: 3.8.5 (default, Aug 23 2020, 18:40:40)  [GCC 10.1.0]
                     platform: Linux-5.10.2-2-MANJARO-x86_64-with-glibc2.29
     optional deps. installed: ['typing-extensions']
from pydantic import validate_arguments


@validate_arguments
def foo(x: int):
    print(x)


def bar(x: int):
    print(x)

>>> foo(1)
1
>>> foo(1, x=2)
2

>>> bar(1)
1
>>> bar(1, x=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bar() got multiple values for argument 'x'

Currently, validate_arguments does not behave the same as a native function when passing in kwargs that override a positional argument.

expectation is that foo(1, x=2) would raise a ValidationError or TypeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions