관리-도구
편집 파일: dataclasses.cpython-38.pyc
U /?�f�F � @ s� d Z ddlZddlZddlZddlmZ ddlmZ zddlmZ W n e k rX Y nX ddl mZmZm Z mZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd lmZmZmZmZ dd lm Z ddl!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' dd l(m)Z)m*Z* ddl+m,Z, e�rVddl(m-Z- ddl.m/Z/m0Z0 eddd�Z1eed df Z2G dd� d�Z3dddddgZ4ed�Z5ej6dk�rVeej7e$fd�edddddddddd d!� e8e8e8e8e8e8eeee9 df ee8 ee8 e8e ee5 gd"f d#�d$d���Z:eej7e$fd�edddddddddd d!� ee5 e8e8e8e8e8e8eeee9 df ee8 ee8 e8d"d%�d&d���Z:n�eej7e$fd�edddddddddd'� e8e8e8e8e8e8eeee9 df ee8 ee8 e ee5 gd"f d(� d)d���Z:eej7e$fd�edddddddddd'� ee5 e8e8e8e8e8e8eeee9 df ee8 ee8 d"d*�d+d���Z:eej7e$fd�dLddddddddddd!� eee5 e8e8e8e8e8e8eeee9 df ee8 ee8 e8ee ee5 gd"f d"f d%�d,d��Z:eed e8eed ddf d-�d.d��Z;G d/d� d�Z<ed ee e8e=dd0�d1d2�Z>d"d3d4�d5d6�Z?ed edd7�d8d9�Z@edfed ee ee= ed: d;�d<d�ZAej6d=k�rpde=e8d>�d?d@�ZBnde=e8d>�dAd@�ZBdddB�dCdD�ZCde=eddE�dFdG�ZDee e8dH�dId�ZEed ee d3dJ�dKd�ZFdS )MaX The main purpose is to enhance stdlib dataclasses by adding validation A pydantic dataclass can be generated from scratch or from a stdlib one. Behind the scene, a pydantic dataclass is just like a regular one on which we attach a `BaseModel` and magic methods to trigger the validation of the data. `__init__` and `__post_init__` are hence overridden and have extra logic to be able to validate input data. When a pydantic dataclass is generated from scratch, it's just a plain dataclass with validation triggered at initialization The tricky part if for stdlib dataclasses that are converted after into pydantic ones e.g. ```py @dataclasses.dataclass class M: x: int ValidatedM = pydantic.dataclasses.dataclass(M) ``` We indeed still want to support equality, hashing, repr, ... as if it was the stdlib one! ```py assert isinstance(ValidatedM(x=1), M) assert ValidatedM(x=1) == M(x=1) ``` This means we **don't want to create a new dataclass that inherits from it** The trick is to create a wrapper around `M` that will act as a proxy to trigger validation without altering default `M` behaviour. � N)�contextmanager)�wraps)�cached_property)� TYPE_CHECKING�Any�Callable�ClassVar�Dict� Generator�Optional�Type�TypeVar�Union�overload)�dataclass_transform)�gather_all_validators)� BaseConfig� ConfigDict�Extra� get_config)�ValidationError)�DataclassTypeError)�Field� FieldInfo�Required� Undefined)�create_model�validate_model)�ClassAttribute)� BaseModel)�CallableGenerator�NoArgAnyCallable� DataclassT� Dataclass)�bound�DataclassProxyc @ s� e Zd ZU eeeef ed<