a DOg@stddlZddlZddlZddlZddlZddlZddlZddlZddlZddlm Z gdZ Gddde Z GdddZ e ZGdd d ZeZeiZGd d d Zed Zed ZedZdZdZdZedZGdddZGdddZGdddZeeddddddddZddZ dd Z!dded!d"d#Z"d$d%Z#d&d'Z$d(d)Z%d*d+Z&d,d-Z'd.d/Z(d0d1Z)d2d3Z*d4d5Z+d6d7Z,d8d9Z-d:d;Z.dd?Z0d@dAZ1dBdCZ2dddde0de1de1e2e1e2e1e2e1e2dDZ3dEdFZ4daddddGdGdGdHdIdJZ5dKdLZ6dMdNZ7dOdPZ8e9dQdRdSZ:dTdUZ;ed[dddddGdGdGd\d]d^Z?d_d`Z@dS)bN) GenericAlias) dataclassfieldFieldFrozenInstanceErrorInitVarMISSINGfieldsasdictastuplemake_dataclassreplace is_dataclassc@s eZdZdS)rN__name__ __module__ __qualname__rr0/opt/alt/python39/lib64/python3.9/dataclasses.pyrrc@seZdZddZdS)_HAS_DEFAULT_FACTORY_CLASScCsdS)Nz rselfrrr__repr__sz#_HAS_DEFAULT_FACTORY_CLASS.__repr__N)rrrrrrrrrsrc@s eZdZdS) _MISSING_TYPENrrrrrrsrc@seZdZddZddZdS) _FIELD_BASEcCs ||_dSNnamerrrrr__init__sz_FIELD_BASE.__init__cCs|jSrrrrrrrsz_FIELD_BASE.__repr__N)rrrr rrrrrrsr_FIELD_FIELD_CLASSVAR_FIELD_INITVARZ__dataclass_fields__Z__dataclass_params__Z __post_init__z^(?:\s*(\w+)\s*\.)?\s*(\w+)c@s(eZdZdZddZddZddZdS) rtypecCs ||_dSrr$)rr%rrrr szInitVar.__init__cCs8t|jtr"t|jts"|jj}n t|j}d|dS)Nzdataclasses.InitVar[]) isinstancer%rrrepr)rZ type_namerrrrs  zInitVar.__repr__cCst|Sr)r)clsr%rrr__class_getitem__szInitVar.__class_getitem__N)rrr __slots__r rr*rrrrrsrc@s0eZdZdZddZddZddZeeZ dS) r) rr%defaultdefault_factoryr(hashinitcomparemetadata _field_typecCsRd|_d|_||_||_||_||_||_||_|dur)rr/r(r?r@rArBrrrr ,s z_DataclassParams.__init__c Cs6d|jd|jd|jd|jd|jd|jd S)Nz_DataclassParams(init=r6z,eq=z,order=z ,unsafe_hash=z,frozen=r7r>rrrrr4sz_DataclassParams.__repr__N)rrrr+r rrrrrr=#sr=Tr,r-r/r(r.r0r1cCs,|tur|turtdt|||||||S)aReturn an object to identify dataclass fields. default is the default value of the field. default_factory is a 0-argument function called to initialize a field's value. If init is True, the field will be a parameter to the class's __init__() function. If repr is True, the field will be included in the object's repr(). If hash is True, the field will be included in the object's hash(). If compare is True, the field will be used in comparison functions. metadata, if specified, must be a mapping which is stored but not otherwise examined by dataclass. It is an error to specify both default and default_factory. z/cannot specify both default and default_factory)r ValueErrorrrCrrrrBs rcs(|sdSddfdd|DdS)N()(,csg|]}d|jqS).r.0fobj_namerr arz_tuple_str..,))join)rMr rrLr _tuple_strXsrQcs"ttfdd}|S)Nc sNt|tf}|vrdS|z|}W|n |0|S)Nz...)id_thread get_identadddiscard)rkeyresult repr_running user_functionrrwrapperks  z _recursive_repr..wrapper)set functoolswraps)r[r\rrYr_recursive_reprfs r`)globalslocals return_typec Cs|dur i}d|vrt|d<d}|tur4||d<d}d|}ddd|D}d |d |d |d |}d |}d|d|d|}i} t||| | dfi|S)NZBUILTINSZ _return_typez->_return_typerG css|]}d|VqdS)z Nr)rJbrrr rz_create_fn..z def rFr7z: , zdef __create_fn__(z): z return Z __create_fn__)builtinsrrPkeysexec) rargsbodyrarbrcZreturn_annotationZtxtZ local_varsnsrrr _create_fnys   rocCs0|rd|d|d|dS|d|d|S)NzBUILTINS.object.__setattr__(rGr7rH=r)rBrvalue self_namerrr _field_assignsrscCsd|j}|jturV|jr@|j||<|d|jd|j}q|j||<|d}n8|jr|jturn|j}q|jtur|j||<|j}ndS|jturdSt||j||S)NZ_dflt_z() if z is _HAS_DEFAULT_FACTORY else rE)rr-rr/r,r2r#rs)rKrBrarrZ default_namerqrrr _field_inits*         rtcCsV|jtur|jturd}n&|jtur2d|j}n|jtur@d}|jd|j|S)Nrdz=_dflt_z=_HAS_DEFAULT_FACTORYz:_type_)r,rr-r)rKr,rrr _init_params  ruc Csd}|D]:}|jr|jtur&|jtus,d}q|rtd|jdqdd|D}|ttdg}|D] }t||||} | rj| | qj|rd d d |D} | |d t d | d |sdg}t d|gdd|D|||ddS)NFTznon-default argument z follows default argumentcSsi|]}d|j|jqS)Z_type_)rr%rIrrr rz_init_fn..)r_HAS_DEFAULT_FACTORYrGcss|]}|jtur|jVqdSr)r2r#rrIrrrrg s z_init_fn..rHrFr7passr cSsg|]}|jrt|qSr)r/rurIrrrrNrz_init_fn..)rbrarc) r/r,rr- TypeErrorrupdaterwrtappendrP_POST_INIT_NAMEro) r rB has_post_initrrraZ seen_defaultrKrbZ body_lineslineZ params_strrrr_init_fns: rcCs2tdddddd|Ddg|d}t|S) Nrrz(return self.__class__.__qualname__ + f"(rhcSs g|]}|jd|jdqS)z={self.z!r}rrIrrrrNsz_repr_fn..z)"ra)rorPr`)r rafnrrr_repr_fns rcCsp|td}|r,dddd|Dd}nd}tdd d |d d d f||dtddd |d ddf||dfS)N)r)rrFrGcss|]}t|jVqdSr)r(rrIrrrrg*rz'_frozen_get_del_attr..rOrE __setattr__)rrrqz if type(self) is cls or name in :z> raise FrozenInstanceError(f"cannot assign to field {name!r}")z)super(cls, self).__setattr__(name, value))rbra __delattr__rz; raise FrozenInstanceError(f"cannot delete field {name!r}")z"super(cls, self).__delattr__(name))rrPro)r)r rarbZ fields_strrrr_frozen_get_del_attr&s2  rcCs$t|ddd|||dg|dS)N)rotherz%if other.__class__ is self.__class__:z return zreturn NotImplementedr)ro)rop self_tuple other_tuplerarrr_cmp_fn?srcCs$td|}tddd|dg|dS)Nr__hash__rz return hash(r7r)rQro)r rarrrr_hash_fnMs   rcCs$||jup"t||juo"|j|juSr)ClassVarr% _GenericAlias __origin__)a_typetypingrrr _is_classvarUs  rcCs||jupt||juSr)rr%)r dataclassesrrr _is_initvar]s  rc Cst|}|rd}|d}|s2tj|jj}n2tj|j}|rd|j||urdtj|jj}|r|||d|rdSdS)NTF)_MODULE_IDENTIFIER_REmatchgroupsysmodulesgetr__dict__) annotationr)Za_modulerZis_type_predicaterrnZ module_namemodulerrr_is_typeds)  rcCs8t||t}t|tr|}nt|tjr,t}t|d}||_||_t |_ t j d}|rt||st|jtrt|j|||jtrt|_ |j t urt j t}t||st|jtrt|j|||jtrt|_ |j ttfvr|jturtd|jd|j t ur4t|jtttfr4tdt|jd|jd|S)N)r,rfield z cannot have a default factoryzmutable default z for field z$ is not allowed: use default_factory)r9rr'rr4MemberDescriptorTyperrr%r!r2rrrrstrrrr"rrrr#r-ryr,listdictr]rD)r)Za_namerr,rKrrrrr _get_fieldsJ              rcCs||jvrdSt|||dS)NTF)rsetattr)r)rrqrrr_set_new_attributes  rcCsdSrrr)r rarrr_hash_set_nonesrcCsdd|D}t||S)NcSs(g|] }|jdur|jrn|jr|qSr)r.r0rIrrrrNrz_hash_add..)r)r)r rafldsrrr _hash_addsrcCstd|jdS)Nz-Cannot overwrite attribute __hash__ in class )ryrrrrr_hash_exceptionsr))FFFF)FFFT)FFTF)FFTT)FTFF)FTFT)FTTF)FTTT)TFFF)TFFT)TFTF)TFTT)TTFF)TTFT)TTTF)TTTTc si}jtjvr tjjj}ni}ttt||||||d} d} jdddD]D} t| t d} | durVd} | D]} | || j <qzt| tj rVd} qVj di}fdd|D}|D]L} | || j <tt| j dtr| jturt| j qt| j | jqĈjD].\}}t|tr||vrt|dq| rz| rf|sftd | sz|rztd tt |j d t}|tup|duod jv }|r|std |rtt}dd| D}tdt|||d|vrdnd|dd| D}|rHdd|D}tdt|||rdd|D}td|}td|}td td d|||d|rdd|D}td|}td|}dD]>\}}t|t|||||drtd|djdq|r8t||D].}t|j|rtd|jdjqtt |t |t ||f}|rh|||_!tdsjt"t#$%dd _&S)!NFrT__annotations__csg|]\}}t||qSr)r)rJrr%r)rrrN_sz"_process_class..z& is a field but has no type annotationz5cannot inherit non-frozen dataclass from a frozen onez5cannot inherit frozen dataclass from a non-frozen oner__eq__z eq must be true if order is truecSsg|]}|jttfvr|qSr)r2r!r#rIrrrrNsr rZ__dataclass_self__cSsg|]}|jtur|qSrr2r!rIrrrrNrcSsg|]}|jr|qSr)r(rIrrrrNrrcSsg|]}|jr|qSrr0rIrrrrNrrz==rcSsg|]}|jr|qSrrrIrrrrNr))__lt__<)__le__z<=)__gt__>)__ge__z>=zCannot overwrite attribute z in class z). Consider using functools.total_ordering__doc__z -> Nonerd)'rrrrr_PARAMSr=__mro__r9_FIELDSvaluesrrBritemsr'rr,rdelattrryrDhasattrr|rrrrQrrr _hash_actionboolrrinspectZ signaturer r)r)r/r(r?r@rArBr raZany_frozen_baseZhas_dataclass_basesrfZ base_fieldsrKZcls_annotationsZ cls_fieldsrrqZ class_hashZhas_explicit_hashr}rZ field_listrrrrZ hash_actionrrr_process_class)s                        rFr>cs*fdd}|dur"|S||S)aReturns the same class as was passed in, with dunder methods added based on the fields defined in the class. Examines PEP 526 __annotations__ to determine fields. If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comparison dunder methods are added. If unsafe_hash is true, a __hash__() method function is added. If frozen is true, fields may not be assigned to after instance creation. cst|Sr)rrr?rBr/r@r(rArrwrapszdataclass..wrapNr)r)r/r(r?r@rArBrrrrrsrcCs@zt|t}Wnty(tdYn0tdd|DS)zReturn a tuple describing the fields of this dataclass. Accepts a dataclass or an instance of one. Tuple elements are of type Field. z0must be called with a dataclass type or instancecss|]}|jtur|VqdSrrrIrrrrgrzfields..)r9rAttributeErrorrytupler)Zclass_or_instancer rrrr s  r cCstt|tS)z2Returns True if obj is an instance of a dataclass.)rr%r)objrrr_is_dataclass_instancesrcCs*t|trt|ts|nt|}t|tS)zEReturns True if obj is a dataclass or an instance of a dataclass.)r'r%rrr)rr)rrrrs r dict_factorycCst|stdt||S)aReturn the fields of a dataclass instance as a new dictionary mapping field names to field values. Example usage: @dataclass class C: x: int y: int c = C(1, 2) assert asdict(c) == {'x': 1, 'y': 2} If given, 'dict_factory' will be used instead of built-in dict. The function applies recursively to field values that are dataclass instances. This will also look into built-in containers: tuples, lists, and dicts. z0asdict() should be called on dataclass instances)rry _asdict_inner)rrrrrr sr cst|rDg}t|D]&}tt||j}||j|fq|St|trrt|drrt |fdd|DSt|t tfrt |fdd|DSt|t rt |fdd| DSt |SdS)N_fieldscsg|]}t|qSrrrJvrrrrNQrz!_asdict_inner..c3s|]}t|VqdSrrrrrrrgVrz _asdict_inner..c3s&|]\}}t|t|fVqdSrrrJkrrrrrgXs)rr rr9rr{r'rrr%rrrcopydeepcopy)rrrXrKrqrrrr6s  r tuple_factorycCst|stdt||S)aReturn the fields of a dataclass instance as a new tuple of field values. Example usage:: @dataclass class C: x: int y: int c = C(1, 2) assert astuple(c) == (1, 2) If given, 'tuple_factory' will be used instead of built-in tuple. The function applies recursively to field values that are dataclass instances. This will also look into built-in containers: tuples, lists, and dicts. z1astuple() should be called on dataclass instances)rry_astuple_inner)rrrrrr _sr cst|r>g}t|D] }tt||j}||q|St|trlt|drlt |fdd|DSt|t tfrt |fdd|DSt|t rt |fdd| DSt |SdS)Nrcsg|]}t|qSrrrrrrrNrz"_astuple_inner..c3s|]}t|VqdSrrrrrrrgrz!_astuple_inner..c3s&|]\}}t|t|fVqdSrrrrrrrgs)rr rr9rr{r'rrr%rrrrr)rrrXrKrqrrrrws   rr)bases namespacer/r(r?r@rArBc sdurint} i} |D]} t| tr<| } d}nDt| dkrR| \} }n.t| dkrr| \} }}|| <ntd| t| tr| std| t| rtd| | | vrtd| | | || | <q$| d <t ||ifd d }t ||||||| d S) aReturn a new dynamically created dataclass. The dataclass name will be 'cls_name'. 'fields' is an iterable of either (name), (name, type) or (name, type, Field) objects. If type is omitted, use the string 'typing.Any'. Field objects are created by the equivalent of calling 'field(name, type [, Field-info])'. C = make_dataclass('C', ['x', ('y', int), ('z', int, field(init=False))], bases=(Base,)) is equivalent to: @dataclass class C(Base): x: 'typing.Any' y: int z: int = field(init=False) For the bases and namespace parameters, see the builtin type() function. The parameters init, repr, eq, order, unsafe_hash, and frozen are passed to dataclass(). Nz typing.AnyrzInvalid field: z'Field names must be valid identifiers: z"Field names must not be keywords: zField name duplicated: rcs |Sr)rz)rnrrrrz make_dataclass..r>) rr]r'rlenry isidentifierkeyword iskeywordrUr4 new_classr)cls_namer rrr/r(r?r@rArBseenZannsitemrtpspecr)rrrr s8          r cKst|stdt|tD]v}|jtur.q|jsR|j|vrt d|jdq|j|vr|jt ur|j t urt d|jdt||j||j<q|j fi|S)a,Return a new object replacing specified fields with new values. This is especially useful for frozen classes. Example usage: @dataclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = replace(c, x=3) assert c1.x == 3 and c1.y == 2 z1replace() should be called on dataclass instancesrzC is declared with init=False, it cannot be specified with replace()zInitVar z! must be specified with replace())rryr9rrr2r"r/rrDr#r,r __class__)rZchangesrKrrrr s   r )N)Arerrr4rrrir^rSr__all__rrrrwrrr5r3rr!r"r#rrr|compilerrrr=rrQr`rorsrtrurrrrrrrrrrrrrrrrr rrrr rrr rr r rrrrs   <   62 ;R>  ) B