PATH:
opt
/
hc_python
/
lib
/
python3.12
/
site-packages
/
pydantic
"""Decorator for validating function calls.""" from __future__ import annotations as _annotations import functools from typing import TYPE_CHECKING, Any, Callable, TypeVar, overload from ._internal import _typing_extra, _validate_call __all__ = ('validate_call',) if TYPE_CHECKING: from .config import ConfigDict AnyCallableT = TypeVar('AnyCallableT', bound=Callable[..., Any]) @overload def validate_call( *, config: ConfigDict | None = None, validate_return: bool = False ) -> Callable[[AnyCallableT], AnyCallableT]: ... @overload def validate_call(func: AnyCallableT, /) -> AnyCallableT: ... def validate_call( func: AnyCallableT | None = None, /, *, config: ConfigDict | None = None, validate_return: bool = False, ) -> AnyCallableT | Callable[[AnyCallableT], AnyCallableT]: """Usage docs: https://docs.pydantic.dev/2.8/concepts/validation_decorator/ Returns a decorated wrapper around the function that validates the arguments and, optionally, the return value. Usage may be either as a plain decorator `@validate_call` or with arguments `@validate_call(...)`. Args: func: The function to be decorated. config: The configuration dictionary. validate_return: Whether to validate the return value. Returns: The decorated function. """ local_ns = _typing_extra.parent_frame_namespace() def validate(function: AnyCallableT) -> AnyCallableT: if isinstance(function, (classmethod, staticmethod)): name = type(function).__name__ raise TypeError(f'The `@{name}` decorator should be applied after `@validate_call` (put `@{name}` on top)') validate_call_wrapper = _validate_call.ValidateCallWrapper(function, config, validate_return, local_ns) @functools.wraps(function) def wrapper_function(*args, **kwargs): return validate_call_wrapper(*args, **kwargs) wrapper_function.raw_function = function # type: ignore return wrapper_function # type: ignore if func: return validate(func) else: return validate
[-] mypy.py
[edit]
[-] typing.py
[edit]
[+]
__pycache__
[-] version.py
[edit]
[-] types.py
[edit]
[-] json.py
[edit]
[-] env_settings.py
[edit]
[-] config.py
[edit]
[-] functional_serializers.py
[edit]
[-] main.py
[edit]
[-] __init__.py
[edit]
[-] validators.py
[edit]
[-] aliases.py
[edit]
[-] alias_generators.py
[edit]
[-] dataclasses.py
[edit]
[-] generics.py
[edit]
[-] fields.py
[edit]
[-] json_schema.py
[edit]
[-] root_model.py
[edit]
[+]
deprecated
[+]
..
[-] functional_validators.py
[edit]
[-] schema.py
[edit]
[-] annotated_handlers.py
[edit]
[-] warnings.py
[edit]
[-] parse.py
[edit]
[-] _migration.py
[edit]
[+]
experimental
[-] py.typed
[edit]
[-] networks.py
[edit]
[-] class_validators.py
[edit]
[-] color.py
[edit]
[-] tools.py
[edit]
[-] error_wrappers.py
[edit]
[-] decorator.py
[edit]
[+]
v1
[+]
_internal
[+]
plugin
[-] datetime_parse.py
[edit]
[-] type_adapter.py
[edit]
[-] utils.py
[edit]
[-] errors.py
[edit]
[-] validate_call_decorator.py
[edit]