# Buggy code
def __init__(self, function: "AnyCallableT", config: "ConfigType"):  # noqa C901
    from inspect import Parameter, signature

    parameters: Mapping[str, Parameter] = signature(function).parameters

    if parameters.keys() & {ALT_V_ARGS, ALT_V_KWARGS, V_POSITIONAL_ONLY_NAME}:
        raise ConfigError(
            f'"{ALT_V_ARGS}", "{ALT_V_KWARGS}" and "{V_POSITIONAL_ONLY_NAME}" are not permitted as argument '
            f'names when using the "{validate_arguments.__name__}" decorator'
        )

    self.raw_function = function
    self.arg_mapping: Dict[int, str] = {}
    self.positional_only_args = set()
    self.v_args_name = "args"
    self.v_kwargs_name = "kwargs"

    type_hints = get_type_hints(function)
    takes_args = False
    takes_kwargs = False
    fields: Dict[str, Tuple[Any, Any]] = {}
    for i, (name, p) in enumerate(parameters.items()):
        if p.annotation == p.empty:
            annotation = Any
        else:
            annotation = type_hints[name]

        default = ... if p.default == p.empty else p.default
        if p.kind == Parameter.POSITIONAL_ONLY:
            self.arg_mapping[i] = name
            fields[name] = annotation, default
            fields[V_POSITIONAL_ONLY_NAME] = List[str], None
            self.positional_only_args.add(name)
        elif p.kind == Parameter.POSITIONAL_OR_KEYWORD:
            self.arg_mapping[i] = name
            fields[name] = annotation, default
        elif p.kind == Parameter.KEYWORD_ONLY:
            fields[name] = annotation, default
        elif p.kind == Parameter.VAR_POSITIONAL:
            self.v_args_name = name
            fields[name] = Tuple[annotation, ...], None
            takes_args = True
        else:
            assert p.kind == Parameter.VAR_KEYWORD, p.kind
            self.v_kwargs_name = name
            fields[name] = Dict[str, annotation], None  # type: ignore
            takes_kwargs = True

    # these checks avoid a clash between "args" and a field with that name
    if not takes_args and self.v_args_name in fields:
        self.v_args_name = ALT_V_ARGS

    # same with "kwargs"
    if not takes_kwargs and self.v_kwargs_name in fields:
        self.v_kwargs_name = ALT_V_KWARGS

    if not takes_args:
        # we add the field so validation below can raise the correct exception
        fields[self.v_args_name] = List[Any], None

    if not takes_kwargs:
        # same with kwargs
        fields[self.v_kwargs_name] = Dict[Any, Any], None

    self.create_model(fields, takes_args, takes_kwargs, config)


# Traceback (TypeError)
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'

# Fixed code
def __init__(self, function: "AnyCallableT", config: "ConfigType"):  # noqa C901
    from inspect import Parameter, signature

    parameters: Mapping[str, Parameter] = signature(function).parameters

    if parameters.keys() & {
        ALT_V_ARGS,
        ALT_V_KWARGS,
        V_POSITIONAL_ONLY_NAME,
        V_DUPLICATE_KWARGS,
    }:
        raise ConfigError(
            f'"{ALT_V_ARGS}", "{ALT_V_KWARGS}", "{V_POSITIONAL_ONLY_NAME}" and "{V_DUPLICATE_KWARGS}" '
            f'are not permitted as argument names when using the "{validate_arguments.__name__}" decorator'
        )

    self.raw_function = function
    self.arg_mapping: Dict[int, str] = {}
    self.positional_only_args = set()
    self.v_args_name = "args"
    self.v_kwargs_name = "kwargs"

    type_hints = get_type_hints(function)
    takes_args = False
    takes_kwargs = False
    fields: Dict[str, Tuple[Any, Any]] = {}
    for i, (name, p) in enumerate(parameters.items()):
        if p.annotation == p.empty:
            annotation = Any
        else:
            annotation = type_hints[name]

        default = ... if p.default == p.empty else p.default
        if p.kind == Parameter.POSITIONAL_ONLY:
            self.arg_mapping[i] = name
            fields[name] = annotation, default
            fields[V_POSITIONAL_ONLY_NAME] = List[str], None
            self.positional_only_args.add(name)
        elif p.kind == Parameter.POSITIONAL_OR_KEYWORD:
            self.arg_mapping[i] = name
            fields[name] = annotation, default
            fields[V_DUPLICATE_KWARGS] = List[str], None
        elif p.kind == Parameter.KEYWORD_ONLY:
            fields[name] = annotation, default
        elif p.kind == Parameter.VAR_POSITIONAL:
            self.v_args_name = name
            fields[name] = Tuple[annotation, ...], None
            takes_args = True
        else:
            assert p.kind == Parameter.VAR_KEYWORD, p.kind
            self.v_kwargs_name = name
            fields[name] = Dict[str, annotation], None  # type: ignore
            takes_kwargs = True

    # these checks avoid a clash between "args" and a field with that name
    if not takes_args and self.v_args_name in fields:
        self.v_args_name = ALT_V_ARGS

    # same with "kwargs"
    if not takes_kwargs and self.v_kwargs_name in fields:
        self.v_kwargs_name = ALT_V_KWARGS

    if not takes_args:
        # we add the field so validation below can raise the correct exception
        fields[self.v_args_name] = List[Any], None

    if not takes_kwargs:
        # same with kwargs
        fields[self.v_kwargs_name] = Dict[Any, Any], None

    self.create_model(fields, takes_args, takes_kwargs, config)