U
    gy                    @  s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZmZ d dlmZ d dlmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZ dd	lm Z m!Z!m"Z"m#Z# e$j%Z&d
Z'dZ(dZ)e
*i Z+e$ Z,e-ej.ej/Z0G dd dej1Z2e2j3Z3G dd de4Z5e3ddddddddddddddfddZ6dddddddddZ7ddddddddd Z8dd!d"d#d$d%Z9G d&d' d'eZ:d(d) Z;d*d+ Z<d,d-d.d/Z=d0d1 Z>d'd-d2d3Z?d4d5 Z@d6d7 ZAd8d9 ZBd:d; ZCG d<d= d=ZDd>d? ZEd@dA ZFddBdCZGddDdEZHeHZIdFdG ZJd"dddHdIdJZKd"dKdLdLdMdNdOdPZLd"dKdQdRdSZMdTdU ZNdVdMdWdXdYZOdZd[ ZPdd\d]ZQdMd-d^d_ZRdd`daZSdbdc ZTddde ZUdfdg Z/dhdi ZVdjd-dkdlZWdddLddmdndoZXdddLdpddqdrdsZYdddLddtdudvZZdddLdpddqdwdxZ[dLdLdydzd{d|Z\dKdLdLdLdLdLdLdydLdLdLddjd}d~dZ]dddddZ^G dd dZ_dd e_j`D ZaeMeQeSe_eaddd eaD ddd eaD dZ_G dd dZbeQeSebZbG dd dZcdd ecj`D ZdeMeQeSeceddeddeddZcG ddp dpZedd dD ZdeMeQeSeeeddeddeddZee$fdfddZfeHdddG dd dZgdd Zhdd Z-dS )    )annotationsN)CallableMapping)cached_property)Any
NamedTupleTypeVar   )_compat_configsetters)PY_3_10_PLUSPY_3_11_PLUSPY_3_13_PLUS_AnnotationExtractor_get_annotationsget_generic_base)DefaultAlreadySetErrorFrozenInstanceErrorNotAnAttrsClassErrorUnannotatedAttributeErrorz__attr_factory_%s)ztyping.ClassVarz
t.ClassVarClassVarztyping_extensions.ClassVarZ_attrs_cached_hashc                   @  s(   e Zd ZdZe Zdd Zdd ZdS )_NothingaF  
    Sentinel to indicate the lack of a value when `None` is ambiguous.

    If extending attrs, you can use ``typing.Literal[NOTHING]`` to show
    that a value may be ``NOTHING``.

    .. versionchanged:: 21.1.0 ``bool(NOTHING)`` is now False.
    .. versionchanged:: 22.2.0 ``NOTHING`` is now an ``enum.Enum`` variant.
    c                 C  s   dS )NNOTHING selfr   r   ./tmp/pip-unpacked-wheel-4g8m5gbg/attr/_make.py__repr__J   s    z_Nothing.__repr__c                 C  s   dS )NFr   r   r   r   r   __bool__M   s    z_Nothing.__bool__N)	__name__
__module____qualname____doc__enumautor   r   r   r   r   r   r   r   =   s   
r   c                   @  s"   e Zd ZdZeddfddZdS )_CacheHashWrappera  
    An integer subclass that pickles / copies as None

    This is used for non-slots classes with ``cache_hash=True``, to avoid
    serializing a potentially (even likely) invalid hash value. Since `None`
    is the default value for uncalculated hashes, whenever this is copied,
    the copy's value for the hash should automatically reset.

    See GH #613 for more details.
    Nr   c                 C  s   ||fS Nr   )r   Z_none_constructor_argsr   r   r   
__reduce__e   s    z_CacheHashWrapper.__reduce__)r    r!   r"   r#   typer)   r   r   r   r   r&   Y   s   r&   TFc                 C  s   t |||d\}}}}|dk	r:|dk	r:|dk	r:d}t||	dk	rr| tk	rVd}t|t|	sjd}t|t|	} |dkr~i }t|ttfrt	j
| }|rt|ttfrt| }|rt|ttfrt
| }t| ||d||||||
||||||dS )a  
    Create a new field / attribute on a class.

    Identical to `attrs.field`, except it's not keyword-only.

    Consider using `attrs.field` in new code (``attr.ib`` will *never* go away,
    though).

    ..  warning::

        Does **nothing** unless the class is also decorated with
        `attr.s` (or similar)!


    .. versionadded:: 15.2.0 *convert*
    .. versionadded:: 16.3.0 *metadata*
    .. versionchanged:: 17.1.0 *validator* can be a ``list`` now.
    .. versionchanged:: 17.1.0
       *hash* is `None` and therefore mirrors *eq* by default.
    .. versionadded:: 17.3.0 *type*
    .. deprecated:: 17.4.0 *convert*
    .. versionadded:: 17.4.0
       *converter* as a replacement for the deprecated *convert* to achieve
       consistency with other noun-based arguments.
    .. versionadded:: 18.1.0
       ``factory=f`` is syntactic sugar for ``default=attr.Factory(f)``.
    .. versionadded:: 18.2.0 *kw_only*
    .. versionchanged:: 19.2.0 *convert* keyword argument removed.
    .. versionchanged:: 19.2.0 *repr* also accepts a custom callable.
    .. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
    .. versionadded:: 19.2.0 *eq* and *order*
    .. versionadded:: 20.1.0 *on_setattr*
    .. versionchanged:: 20.3.0 *kw_only* backported to Python 2
    .. versionchanged:: 21.1.0
       *eq*, *order*, and *cmp* also accept a custom callable
    .. versionchanged:: 21.1.0 *cmp* undeprecated
    .. versionadded:: 22.2.0 *alias*
    TNF6Invalid value for hash.  Must be True, False, or None.z=The `default` and `factory` arguments are mutually exclusive.z*The `factory` argument must be a callable.)default	validatorreprcmphashinit	convertermetadatar*   kw_onlyeqeq_keyorder	order_key
on_setattralias)_determine_attrib_eq_order	TypeErrorr   
ValueErrorcallableFactory
isinstancelisttupler   pipeand__CountingAttr)r,   r-   r.   r/   r0   r1   r3   r*   r2   factoryr4   r5   r7   r9   r:   r6   r8   msgr   r   r   attribi   sX    7   
rH    strzdict[str, Any] | NonezMapping[str, object] | NoneNone)scriptglobslocsfilenamereturnc                 C  s   t | |d}t||| dS )z[
    Evaluate the script with the given global (globs) and local (locs)
    variables.
    execN)compileeval)rL   rM   rN   rO   bytecoder   r   r   _compile_and_eval   s    
rU   zdict[str, Any])rL   rO   rM   localsrP   c           	      C  sz   |dkri n|}d}|}t | d| d|f}tj||}||krFqh|dd  d| d}|d7 }qt| ||| |S )zP
    Cache the script with _linecache_, compile it and return the _locals_.
    Nr	   T->)len
splitlines	linecachecache
setdefaultrU   )	rL   rO   rM   rV   rN   countbase_filenameZlinecache_tupleZold_valr   r   r   _linecache_and_compile   s    

ra   z	list[str]r*   )cls_name
attr_namesrP   c                 C  sF   |  d}i }t |D ] \}}|fdd}t|||< qt|tf|S )z
    Create a tuple subclass to hold `Attribute`s for an `attrs` class.

    The subclass is a bare tuple with properties for names.

    class MyClassAttributes(tuple):
        __slots__ = ()
        x = property(itemgetter(0))
    Z
Attributesc                 S  s   | | S r'   r   )r   ir   r   r   getter  s    z&_make_attr_tuple_class.<locals>.getter)	enumeratepropertyr*   rB   )rb   rc   Zattr_class_namebodyrd   	attr_namere   r   r   r   _make_attr_tuple_class  s    

rj   c                   @  s&   e Zd ZU ded< ded< ded< dS )_Attributesr*   attrslist[Attribute]
base_attrsdict[str, type]Zbase_attrs_mapN)r    r!   r"   __annotations__r   r   r   r   rk     s   
rk   c                 C  s2   t | } | dr(| dr(| dd } | tS )z
    Check whether *annot* is a typing.ClassVar.

    The string comparison hack is used to avoid evaluating all string
    annotations which would put attrs-based classes at a performance
    disadvantage compared to plain old classes.
    )'"r	   rW   )rJ   
startswithendswith_CLASSVAR_PREFIXES)Zannotr   r   r   _is_class_var"  s    rv   c                 C  s
   || j kS )zR
    Check whether *cls* defines *attrib_name* (and doesn't just inherit it).
    )__dict__)clsZattrib_namer   r   r   _has_own_attribute3  s    ry   z'tuple[list[Attribute], dict[str, type]]rP   c                 C  s   g }i }t | jdd D ]H}t|dg D ]6}|js*|j|kr@q*|jdd}|| |||j< q*qg }t }t |D ](}|j|krqv|d| |	|j qv||fS )zQ
    Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
    r	   rW   __attrs_attrs__T	inheritedr   )
reversed__mro__getattrr}   nameevolveappendsetinsertadd)rx   taken_attr_namesrn   base_attr_mapbase_clsafilteredseenr   r   r   _collect_base_attrs:  s"    

r   c                 C  sn   g }i }| j dd D ]N}t|dg D ]<}|j|kr6q&|jdd}||j || |||j< q&q||fS )a-  
    Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.

    N.B. *taken_attr_names* will be mutated.

    Adhere to the old incorrect behavior.

    Notably it collects from the front and considers inherited attributes which
    leads to the buggy behavior reported in #428.
    r	   rW   r{   Tr|   )r   r   r   r   r   r   )rx   r   rn   r   r   r   r   r   r   _collect_base_attrs_broken[  s    

r   c              	     s0  | j t|  |dk	r$t| }n|dkrdd  D }g }t }  D ]H\}	}
t|
rbqP||	 |	t}|j	t
k	rt|}||	|f qP|| }|rtddt|fddd	 d
 ntdd  D dd d	}tj fdd|D }|r&t| dd |D \}}nt| dd |D \}}|r`dd |D }dd |D }|| }|dk	rt|| |}d}dd |D D ]H}|dkr|jtkrd|}t||dkr|jtk	rd}q|D ]$}|jst|dt|j qdd |D }t| j|}t||||S )a3  
    Transform all `_CountingAttr`s on a class into `Attribute`s.

    If *these* is passed, use that and don't look for them on the class.

    If *collect_by_mro* is True, collect them in the correct MRO order,
    otherwise use the old -- incorrect -- order.  See #428.

    Return an `_Attributes`.
    NTc                 S  s   h | ]\}}|j tkr|qS r   	__class__rE   .0r   attrr   r   r   	<setcomp>  s   
z#_transform_attrs.<locals>.<setcomp>z1The following `attr.ib`s lack a type annotation: , c                   s     | jS r'   )getcounter)n)cdr   r   <lambda>      z"_transform_attrs.<locals>.<lambda>)key.c                 s  s$   | ]\}}|j tkr||fV  qd S r'   r   r   r   r   r   	<genexpr>  s   
z#_transform_attrs.<locals>.<genexpr>c                 S  s
   | d j S Nr	   )r   )er   r   r   r     r   c                   s"   g | ]\}}||  |qS r   )r   )r   ri   ca)annsfcar   r   
<listcomp>  s    z$_transform_attrs.<locals>.<listcomp>c                 S  s   h | ]
}|j qS r   r   r   r   r   r   r   r     s     c                 S  s   h | ]
}|j qS r   r   r   r   r   r   r     s     c                 S  s   g | ]}|j d dqS T)r4   r   r   r   r   r   r     s     c                 S  s   g | ]}|j d dqS r   r   r   r   r   r   r     s     Fc                 s  s&   | ]}|j d k	r|jd kr|V  qdS )FN)r1   r4   r   r   r   r   r     s     
 
 zlNo mandatory attributes allowed after an attribute with a default value or factory.  Attribute in question: r:   c                 S  s   g | ]
}|j qS r   r   r   r   r   r   r     s     )rw   r   rA   itemsr   rv   r   r   r   r   rE   rH   r   r   joinsorted	Attributefrom_counting_attrr   r   rB   r,   r=   r:   _OBJ_SETATTR__get___default_init_alias_forr   rj   r    rk   )rx   theseauto_attribsr4   collect_by_mrofield_transformerZca_listZca_namesZannot_namesri   r*   r   ZunannotatedZ	own_attrsrn   r   rl   Zhad_defaultrG   rc   Z
AttrsClassr   )r   r   r   r   _transform_attrsw  s    

	 
 

r   c              
   C  s   ddddddddd	g	}|d k	r*| d
 n|ddddddddg |ddg t|d}| tj|d}td|||d|idd S )Nzdef wrapper(_cls):z    __class__ = _clsz    def __getattr__(self, item, cached_properties=cached_properties, original_getattr=original_getattr, _cached_setattr_get=_cached_setattr_get):z+         func = cached_properties.get(item)z         if func is not None:z!              result = func(self)z1              _setter = _cached_setattr_get(self)z#              _setter(item, result)z              return resultz,         return original_getattr(self, item)z         try:z2             return super().__getattribute__(item)z         except AttributeError:z4             if not hasattr(super(), '__getattr__'):z                 raisez-             return super().__getattr__(item)zY         original_error = f"'{self.__class__.__name__}' object has no attribute '{item}'"z-         raise AttributeError(original_error)z    return __getattr__z__getattr__ = wrapper(_cls)r   )cached_properties_cached_setattr_getoriginal_getattr
_cls)rV   __getattr__)r   extend_generate_unique_filenamer   r   ra   r   )r   r   rx   linesZunique_filenameglobr   r   r   _make_cached_property_getattr  sV    
   r   c                 C  s,   t | tr$|dkr$t| || dS tdS )z4
    Attached to frozen classes as __setattr__.
    )	__cause____context____traceback____suppress_context__	__notes__N)r@   BaseException__setattr__r   r   r   valuer   r   r   _frozen_setattrs  s    r   c                 C  s*   t | tr"|dkr"t| | dS tdS )z4
    Attached to frozen classes as __delattr__.
    )r   N)r@   r   __delattr__r   )r   r   r   r   r   _frozen_delattrs(  s    r   c            	      O  s   z
| \}W n. t k
r8   dt|  d}t|dY nX |j}t|}|D ].}|jsXqL|j}|j}||krLt||||< qL|f |S )a  
    Create a new instance, based on the first positional argument with
    *changes* applied.

    .. tip::

       On Python 3.13 and later, you can also use `copy.replace` instead.

    Args:

        inst:
            Instance of a class with *attrs* attributes. *inst* must be passed
            as a positional argument.

        changes:
            Keyword changes in the new copy.

    Returns:
        A copy of inst with *changes* incorporated.

    Raises:
        TypeError:
            If *attr_name* couldn't be found in the class ``__init__``.

        attrs.exceptions.NotAnAttrsClassError:
            If *cls* is not an *attrs* class.

    .. versionadded:: 17.1.0
    .. deprecated:: 23.1.0
       It is now deprecated to pass the instance using the keyword argument
       *inst*. It will raise a warning until at least April 2024, after which
       it will become an error. Always pass the instance as a positional
       argument.
    .. versionchanged:: 24.1.0
       *inst* can't be passed as a keyword argument anymore.
    z*evolve() takes 1 positional argument, but z were givenN)	r=   rZ   r<   r   fieldsr1   r   r:   r   )	argschangesinstrG   rx   rl   r   ri   Z	init_namer   r   r   r   3  s     %
r   c                   @  s   e Zd ZdZdZddddZdd Zd	d
ddZdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d+d,d-d.Zd+d+d,d/d0Zd1S )2_ClassBuilderz(
    Iteratively build *one* class.
    )_add_method_dunders_attr_names_attrs_base_attr_map_base_names_cache_hashr   	_cls_dict_delete_attribs_frozen_has_custom_setattr_has_post_init_has_pre_init_is_exc_on_setattr_pre_init_has_args_repr_added_script_snippets_slots_weakref_slot_wrote_own_setattrr*   rx   c                 C  s  t ||||||\}}}|| _|r,t|jni | _|| _dd |D | _|| _tdd |D | _	|| _
|| _|| _|	| _tt|dd| _d| _| jr|j}t|}t|jdk| _tt|dd| _t| | _|
| _|| _|| _d| _| j| jd	< |rt| jd
< t| jd< d| _n|tt j!t j"fkrd }}|D ]8}|j#d k	rPd}|j$d k	r`d}|r<|r< qvq<|tkr|s|r|t j!kr|r|t j"kr|sd | _|r| % \| jd< | jd< g | _&d| _'t(| jdrt(| jds| j)| _*n| j+| _*d S )Nc                 S  s   h | ]
}|j qS r   r   r   r   r   r   r     s     z)_ClassBuilder.__init__.<locals>.<setcomp>c                 s  s   | ]}|j V  qd S r'   r   r   r   r   r   r     s     z)_ClassBuilder.__init__.<locals>.<genexpr>__attrs_pre_init__Fr	   __attrs_post_init__r{   r   r   T__getstate____setstate__r!   r"   ),r   r   dictrw   r   r   r   r   rB   r   r   r   r   r   boolr   r   r   r   inspect	signaturerZ   
parametersr   r   r   r   r   r   r   r   _DEFAULT_ON_SETATTRr   validateconvertr-   r2   _make_getstate_setstater   r   hasattr_add_method_dunders_safer   _add_method_dunders_unsafe)r   rx   r   slotsfrozenweakref_slotgetstate_setstater   r4   
cache_hashis_excr   r9   Zhas_custom_setattrr   rl   rn   Zbase_mapZpre_init_funcZpre_init_signatureZhas_validatorZhas_converterr   r   r   r   __init__  s    
	



 
z_ClassBuilder.__init__c                 C  s   d| j j dS )Nz<_ClassBuilder(cls=z)>)r   r    r   r   r   r   r     s    z_ClassBuilder.__repr__rK   rz   c                 C  sl   d dd | jD }i }| jD ]\}}}|| q t|t| jd|}| jD ]\}}}|| j| qPdS )z=
        Evaluate any registered snippets in one go.
        r   c                 S  s   g | ]}|d  qS )r   r   )r   Zsnippetr   r   r   r     s     z0_ClassBuilder._eval_snippets.<locals>.<listcomp>methodsN)r   r   updatera   r   r   r   )r   rL   rM   _Zsnippet_globsrN   hookr   r   r   _eval_snippets  s    
z_ClassBuilder._eval_snippetsc                 C  sT   |    | jdkr|  }n|  }tr2t|}t|ddrPd|jkrP|	  |S )z
        Finalize class based on the accumulated configuration.

        Builder cannot be used after calling this method.
        T__attrs_init_subclass__N)
r  r   _create_slots_class_patch_original_classr   abcZupdate_abstractmethodsr   rw   r  )r   rx   r   r   r   build_class
  s    



z_ClassBuilder.build_classc              
   C  s   | j }| j}| jrV| jD ]<}||krt||ttk	rtt t	|| W 5 Q R X q| j
 D ]\}}t||| q`| jst|ddrd|_| jst|_|S )zA
        Apply accumulated methods and return the class.
        __attrs_own_setattr__F)r   r   r   r   r   	_SENTINEL
contextlibsuppressAttributeErrordelattrr   r   setattrr   r  r   r   r   )r   rx   
base_namesr   r   r   r   r   r  "  s*    
  z#_ClassBuilder._patch_original_classc              
     s  fddj  D }jsTd|d< jsTjjD ]  jddr4t|d<  qTq4i }d}jj	dd D ]:  jdd	d	k	rd
}|
 fddt dg D  qltjj}jrdtjddkrd|kr|s|d7 }dd | D }g }|rtj}| D ]F\}}	||f7 }||= ||	 t|	j}
|
tjjk	r|
||< q|d}|d	k	rx|| t||j|d< fdd|D fdd| D fddD |
 jrt t|d< jj|d< tjjjjj|}t|j  |D ]}t!|t"t#frHt|j$dd	}n(t!|t%rdt|j&dd	}nt|dd	}|szq$|D ]:}z|j'jk}W n t(k
r   Y nX |r~||_'q~q$|S )zL
        Build and return a new class with a `__slots__` attribute.
        c                   s(   i | ] \}}|t  jdkr||qS )rw   __weakref__)rw   r  )rB   r   r   kvr   r   r   
<dictcomp>J  s    z5_ClassBuilder._create_slots_class.<locals>.<dictcomp>Fr  r   r	   rW   r  NTc                   s   i | ]}|t  |qS r   r   r   r   )r   r   r   r  i  s    	__slots__r   )r  c                 S  s"   i | ]\}}t |tr||jqS r   )r@   r   func)r   r   Zcached_propr   r   r   r  z  s   
 r   c                   s   g | ]}| kr|qS r   r   r  )r  r   r   r     s      z5_ClassBuilder._create_slots_class.<locals>.<listcomp>c                   s   i | ]\}}| kr||qS r   r   )r   ZslotZslot_descriptor)
slot_namesr   r   r    s    c                   s   g | ]}| kr|qS r   r   r  )reused_slotsr   r   r     s      r"   __closure__))r   r   r   r   r   	__bases__rw   r   r   r   r   r   r   r   r   r   r   r   r   r   return_annotation	Parameteremptyr   r   _HASH_CACHE_FIELDrB   r"   r*   r    	itertoolschainvaluesr@   classmethodstaticmethod__func__rg   fgetcell_contentsr=   )r   r   Zexisting_slotsZweakref_inheritednamesr   Z&additional_closure_functions_to_updateZclass_annotationsr   r  
annotationr   rx   itemZclosure_cellscellmatchr   )r   r  r  r   r  r   r  F  s    









  


 z!_ClassBuilder._create_slots_classc                   s8   t  j|\}} fdd} j|||f d _ S )Nc                   s     |d | d< d S )Nr   r   cls_dictrM   r   r   r   _attach_repr  s    z,_ClassBuilder.add_repr.<locals>._attach_reprT)_make_repr_scriptr   r   r   r   )r   nsrL   rM   r1  r   r   r   add_repr  s
    z_ClassBuilder.add_reprc                 C  s.   | j sd}t|dd }| || jd< | S )Nz3__str__ can only be generated if a __repr__ exists.c                 S  s   |   S r'   r   r   r   r   r   __str__  s    z&_ClassBuilder.add_str.<locals>.__str__r6  )r   r=   r   r   )r   rG   r6  r   r   r   add_str  s    z_ClassBuilder.add_strc                   s<   t dd | jD fdd}| j  fdd}||fS )zF
        Create custom __setstate__ and __getstate__ methods.
        c                 s  s   | ]}|d kr|V  qdS )r  Nr   )r   Zanr   r   r   r     s     z8_ClassBuilder._make_getstate_setstate.<locals>.<genexpr>c                   s    fddD S )9
            Automatically created by attrs.
            c                   s   i | ]}|t  |qS r   r  r  r   r   r   r    s      zQ_ClassBuilder._make_getstate_setstate.<locals>.slots_getstate.<locals>.<dictcomp>r   r   )state_attr_namesr   r   slots_getstate  s    z=_ClassBuilder._make_getstate_setstate.<locals>.slots_getstatec                   sf   t | }t|tr4t|D ]\}}||| qn D ]}||kr8||||  q8 rb|td dS )r8  N)r   r   r@   rB   zipr   )r   stateZ_ClassBuilder__bound_setattrr   r   Zhash_caching_enabledr9  r   r   slots_setstate  s    

z=_ClassBuilder._make_getstate_setstate.<locals>.slots_setstate)rB   r   r   )r   r:  r>  r   r=  r   r     s    z%_ClassBuilder._make_getstate_setstatec                 C  s   d | j d< | S N__hash__)r   r   r   r   r   make_unhashable  s    
z_ClassBuilder.make_unhashablec                   sH   t  j j j jd\}}dddd fdd} j|||f  S )Nr   r   r   rK   )r0  rN   rP   c                   s     |d | d< d S r?  r.  )r0  rN   r   r   r   attach_hash  s    z+_ClassBuilder.add_hash.<locals>.attach_hash)_make_hash_scriptr   r   r   r   r   r   )r   rL   rM   rC  r   r   r   add_hash  s    
z_ClassBuilder.add_hashc                   s`   t jjjjjjjjj	j
jdd\}}  fdd}j|||f S )NF
attrs_initc                   s    |d } |_ || d< d S )Nr   rp   r   r0  rM   r1   r   r   r   r   _attach_init2  s    z,_ClassBuilder.add_init.<locals>._attach_init_make_init_scriptr   r   r   r   r   r   r   r   r   r   r   r   r   )r   rL   rM   rK  r   rJ  r   add_init"  s"    z_ClassBuilder.add_initc                 C  s   |  dd | jd< | S )Nc                 [  s   t | f|S r'   r   )r   r   r   r   r   r   =  r   z+_ClassBuilder.add_replace.<locals>.<lambda>__replace__)r   r   r   r   r   r   add_replace;  s    
z_ClassBuilder.add_replacec                 C  s   t dd | jD | jd< d S )Nc                 s  s    | ]}|j r|js|jV  qd S r'   )r1   r4   r   )r   fieldr   r   r   r   B  s    z/_ClassBuilder.add_match_args.<locals>.<genexpr>__match_args__)rB   r   r   r   r   r   r   add_match_argsA  s    z_ClassBuilder.add_match_argsc                   s`   t jjjjjjjjj	j
jdd\}}  fdd}j|||f S )NTrF  c                   s    |d } |_ || d< d S )N__attrs_init__rH  rI  rJ  r   r   _attach_attrs_initX  s    z8_ClassBuilder.add_attrs_init.<locals>._attach_attrs_initrL  )r   rL   rM   rU  r   rJ  r   add_attrs_initH  s"    z_ClassBuilder.add_attrs_initc                   s>    j }t j\}} fdd} j|||f t|d<  S )Nc                   s     |d | d< d S )N__eq__r.  r/  r   r   r   
_attach_eqf  s    z(_ClassBuilder.add_eq.<locals>._attach_eq__ne__)r   _make_eq_scriptr   r   r   rY  )r   r   rL   rM   rX  r   r   r   add_eqa  s    z_ClassBuilder.add_eqc                   s>    j } fddt j jD \|d< |d< |d< |d<  S )Nc                 3  s   | ]}  |V  qd S r'   r.  )r   methr   r   r   r   r  s   z*_ClassBuilder.add_order.<locals>.<genexpr>__lt____le____gt____ge__)r   _make_orderr   r   )r   r   r   r   r   	add_ordero  s
    
z_ClassBuilder.add_orderc                   s   i  | j D ],}|jp| j}|r
|tjk	r
||f |j< q
 s@| S | jrRd}t| fdd}d| jd< | 	|| jd< d| _
| S )Nz7Can't combine custom __setattr__ with on_setattr hooks.c                   sF   z | \}}W n t k
r(   |}Y nX || ||}t| || d S r'   )KeyErrorr   )r   r   valr   r  nvalZsa_attrsr   r   r     s    
z._ClassBuilder.add_setattr.<locals>.__setattr__Tr  r   )r   r9   r   r   NO_OPr   r   r=   r   r   r   )r   r   r9   rG   r   r   rf  r   add_setattry  s    


z_ClassBuilder.add_setattrr   )methodrP   c                 C  s6   | j j|_| j j d|j |_d| j j d|_|S )z@
        Add __module__ and __qualname__ to a *method*.
        r   $Method generated by attrs for class )r   r!   r"   r    r#   r   ri  r   r   r   r     s
    
z(_ClassBuilder._add_method_dunders_unsafec              	   C  sx   t t | jj|_W 5 Q R X t t | jj d|j |_W 5 Q R X t t d| jj d|_W 5 Q R X |S )zL
        Add __module__ and __qualname__ to a *method* if possible.
        r   rj  )r
  r  r  r   r!   r"   r    r#   rk  r   r   r   r     s     z&_ClassBuilder._add_method_dunders_safeN)r    r!   r"   r#   r  r   r   r  r  r  r  r4  r7  r   rA  rE  rN  rP  rS  rV  r[  rb  rh  r   r   r   r   r   r   r   m  s.   k$ 
)
 r   c                 C  st   | dk	r(t |dk	|dk	fr(d}t|| dk	r8| | fS |dkrD|}|dkrP|}|dkrl|dkrld}t|||fS )
    Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
    values of eq and order.  If *eq* is None, set it to *default_eq*.
    N&Don't mix `cmp` with `eq' and `order`.FT-`order` can only be True if `eq` is True too.anyr=   )r/   r5   r7   
default_eqrG   r   r   r   _determine_attrs_eq_order  s    rr  c           	      C  s   | dk	r(t |dk	|dk	fr(d}t|dd }| dk	rP|| \} }| || |fS |dkrd|d }}n||\}}|dkr|| }}n||\}}|dkr|dkrd}t|||||fS )rl  Nrm  c                 S  s    t | rd|  } }nd}| |fS )z8
        Decide whether a key function is used.
        TN)r>   )r   r   r   r   r   decide_callable_or_boolean  s    z>_determine_attrib_eq_order.<locals>.decide_callable_or_booleanFTrn  ro  )	r/   r5   r7   rq  rG   rs  Zcmp_keyr6   r8   r   r   r   r;     s"    r;   c                 C  sF   |dks|dkr|S |dkr(|dkr(|S |D ]}t | |r, dS q,|S )ap  
    Check whether we should implement a set of methods for *cls*.

    *flag* is the argument passed into @attr.s like 'init', *auto_detect* the
    same as passed into @attr.s and *dunders* is a tuple of attribute names
    whose presence signal that the user has implemented it themselves.

    Return *default* if no reason for either for or against is found.
    TFN)ry   )rx   flagauto_detectZdundersr,   Zdunderr   r   r   _determine_whether_to_implement  s    
rv  c                   s   dk	r"ddl }|jtddd t|||d\|dk	r@|	tttfrXtj  	
fdd}| dkr|S || S )a  
    A class decorator that adds :term:`dunder methods` according to the
    specified attributes using `attr.ib` or the *these* argument.

    Consider using `attrs.define` / `attrs.frozen` in new code (``attr.s`` will
    *never* go away, though).

    Args:
        repr_ns (str):
            When using nested classes, there was no way in Python 2 to
            automatically detect that.  This argument allows to set a custom
            name for a more meaningful ``repr`` output.  This argument is
            pointless in Python 3 and is therefore deprecated.

    .. caution::
        Refer to `attrs.define` for the rest of the parameters, but note that they
        can have different defaults.

        Notably, leaving *on_setattr* as `None` will **not** add any hooks.

    .. versionadded:: 16.0.0 *slots*
    .. versionadded:: 16.1.0 *frozen*
    .. versionadded:: 16.3.0 *str*
    .. versionadded:: 16.3.0 Support for ``__attrs_post_init__``.
    .. versionchanged:: 17.1.0
       *hash* supports `None` as value which is also the default now.
    .. versionadded:: 17.3.0 *auto_attribs*
    .. versionchanged:: 18.1.0
       If *these* is passed, no attributes are deleted from the class body.
    .. versionchanged:: 18.1.0 If *these* is ordered, the order is retained.
    .. versionadded:: 18.2.0 *weakref_slot*
    .. deprecated:: 18.2.0
       ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now raise a
       `DeprecationWarning` if the classes compared are subclasses of
       each other. ``__eq`` and ``__ne__`` never tried to compared subclasses
       to each other.
    .. versionchanged:: 19.2.0
       ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now do not consider
       subclasses comparable anymore.
    .. versionadded:: 18.2.0 *kw_only*
    .. versionadded:: 18.2.0 *cache_hash*
    .. versionadded:: 19.1.0 *auto_exc*
    .. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
    .. versionadded:: 19.2.0 *eq* and *order*
    .. versionadded:: 20.1.0 *auto_detect*
    .. versionadded:: 20.1.0 *collect_by_mro*
    .. versionadded:: 20.1.0 *getstate_setstate*
    .. versionadded:: 20.1.0 *on_setattr*
    .. versionadded:: 20.3.0 *field_transformer*
    .. versionchanged:: 21.1.0
       ``init=False`` injects ``__attrs_init__``
    .. versionchanged:: 21.1.0 Support for ``__attrs_pre_init__``
    .. versionchanged:: 21.1.0 *cmp* undeprecated
    .. versionadded:: 21.3.0 *match_args*
    .. versionadded:: 22.2.0
       *unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
    .. deprecated:: 24.1.0 *repr_ns*
    .. versionchanged:: 24.1.0
       Instances are not compared as tuples of attributes anymore, but using a
       big ``and`` condition. This is faster and has more correct behavior for
       uncomparable values like `math.nan`.
    .. versionadded:: 24.1.0
       If a class has an *inherited* classmethod called
       ``__attrs_init_subclass__``, it is executed after the class is created.
    .. deprecated:: 24.1.0 *hash* is deprecated in favor of *unsafe_hash*.
    Nr   zQThe `repr_ns` argument is deprecated and will be removed in or after August 2025.   )
stacklevelc                   s"  p
t | }dkot| t}o*t| d}|r@|r@d}t|t| |t| dd ||}t| dr| dkr|  t| d}|s|dkr|	  |st| dr|
  s|  	d krdkrt| d	rd
		dk	r(	d
k	r(	d k	r(d}t|	d
ksL	d krF|d
ksL|r`rd}t|nL	dks	d kr|dkr|dkr|  nrd}t||  t| 
dr|  n|  rd}t|trt| ds|  trrt| ds|  | S )NTr   z/Can't freeze a class with a custom __setattr__.)r   r   )r,   r5  )rW  rY  )r]  r^  r_  r`  r@  Fr+   zlInvalid value for cache_hash.  To use hash caching, hashing must be either explicitly or implicitly enabled.r   zFInvalid value for cache_hash.  To use hash caching, init must be True.rO  rR  )_has_frozen_base_class
issubclassr   ry   r=   r   rv  r4  r7  r[  rb  rh  r<   rE  rA  rN  rV  r   rP  r   rS  r  )rx   	is_frozenr   Zhas_own_setattrrG   Zbuilderr5   r   ru  auto_excr   r   Zeq_r   r   r   r0   r1   r4   
match_argsr9   Zorder_r.   repr_nsr   rJ   r   r   r   r   wrap  s        
      $


   
zattrs.<locals>.wrap)	warningswarnDeprecationWarningrr  r@   rA   rB   r   rC   )Z	maybe_clsr   r  r.   r/   r0   r1   r   r   r   rJ   r   r4   r   r~  r5   r7   ru  r   r   r9   r   r  unsafe_hashr  r  r   r}  r   rl     s"    \
4nrl   c                 C  s
   | j tkS )zV
    Check whether *cls* has a frozen ancestor by looking at its
    __setattr__.
    )r   r   r   r   r   r   rz    s    rz  )rx   	func_namerP   c              	   C  s$   d| d| j  dt| d| j dS )zF
    Create a "filename" suitable for a function being generated.
    z<attrs generated  r   r"   rY   )r!   r   r    )rx   r  r   r   r   r   
  s    "r   rm   r   ztuple[str, dict])rx   rl   r   r   rP   c                   s  t dd  D  d}tt| di d}dd|sB|d7 }n |d	7 }|d
7 }d d7 |g fdd}|r|dt d  |r|dt d|d  |d d  n|dt d|d  |dt   n
|d| d}|fS )Nc                 s  s0   | ](}|j d ks$|j dkr|jd kr|V  qdS )TN)r0   r5   r   r   r   r   r     s
    
 
 
 z$_make_hash_script.<locals>.<genexpr>        r0   zdef __hash__(selfzhash((z))z):z, *zC, _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):z_cache_wrapper()c              	     s    ||   |d d g  D ]Z}|jrhd|j d}|j|< |d| d|j d  q&|d|j d  q&|d   d	S )
z
        Generate the code for actually computing the hash code.
        Below this will either be returned directly or used to compute
        a value which is then cached, depending on the value of cache_hash
        r  ,r   _key(self.z),        self.    N)r   r6   r   r   )prefixindentr   cmp_namerl   Zclosing_bracesrM   Z	hash_funcZmethod_linesZ	type_hashr   r   append_hash_computation_lines/  s    

z8_make_hash_script.<locals>.append_hash_computation_lineszif self.z	 is None:zobject.__setattr__(self, '', rw  self. = zreturn self.zreturn r   )rB   r0   r   r   r   r   )rx   rl   r   r   tabZhash_defr  rL   r   r  r   rD    sB    

 
 

rD  )rx   rl   c                 C  s6   t | |ddd\}}t||t| dd |d | _| S )z%
    Add a hash method to *cls*.
    FrB  r@  rO   )rD  rU   r   r@  rx   rl   rL   rM   r   r   r   	_add_hash\  s       
  
r  c                 C  s   |  |}|tkrtS | S )z^
    Check equality and either forward a NotImplemented or
    return the result negated.
    )rW  NotImplemented)r   otherresultr   r   r   rY  j  s    
rY  rA   )rl   rP   c                 C  s   dd | D } dddg}i }| r| d | D ]}|jrzd|j d}|j||< | d	| d
|j d| d|j d	 n| d|j d|j  || d k	r.|d  d|d< q.| d n
| d d|}||fS )z6
    Create __eq__ method for *cls* with *attrs*.
    c                 S  s   g | ]}|j r|qS r   )r5   r   r   r   r   r   z  s      z#_make_eq_script.<locals>.<listcomp>zdef __eq__(self, other):z-    if other.__class__ is not self.__class__:z        return NotImplementedz    return  (r   r  r  r  z) == z(other.r  r  z
 == other.rW   z andz    )z    return Truer   )r   r6   r   r   )rl   r   rM   r   r  rL   r   r   r   rZ  v  s,    

 

rZ  c                   sV   dd  D   fddfdd}fdd}fd	d
}fdd}||||fS )z9
    Create ordering methods for *cls* with *attrs*.
    c                 S  s   g | ]}|j r|qS r   )r7   r   r   r   r   r     s      z_make_order.<locals>.<listcomp>c                   s    t dd  fddD D S )z&
        Save us some typing.
        c                 s  s"   | ]\}}|r||n|V  qd S r'   r   )r   r   r   r   r   r   r     s   z6_make_order.<locals>.attrs_to_tuple.<locals>.<genexpr>c                 3  s    | ]}t  |j|jfV  qd S r'   )r   r   r8   r   objr   r   r     s    )rB   r  rl   r  r   attrs_to_tuple  s
    
z#_make_order.<locals>.attrs_to_tuplec                   s    |j | j kr |  |k S tS z1
        Automatically created by attrs.
        r   r  r   r  r  r   r   r]    s    z_make_order.<locals>.__lt__c                   s    |j | j kr |  |kS tS r  r  r  r  r   r   r^    s    z_make_order.<locals>.__le__c                   s    |j | j kr |  |kS tS r  r  r  r  r   r   r_    s    z_make_order.<locals>.__gt__c                   s    |j | j kr |  |kS tS r  r  r  r  r   r   r`    s    z_make_order.<locals>.__ge__r   )rx   rl   r]  r^  r_  r`  r   )rl   r  r   ra    s    				ra  c                 C  sB   |dkr| j }t|\}}t||t| dd |d | _t| _| S )z5
    Add equality methods to *cls* with *attrs*.
    NrW  r  )r{   rZ  rU   r   rW  rY  r  r   r   r   _add_eq  s      
r  c                 C  s   t dd | D }dd |D }t|d< t|d< t|d< g }|D ]N\}}}|rVd| n
d	| d
 }|tkrvd||f nd|||f }	||	 q@d|}
|dkrd}n|d }ddddddddddddd| d|
 ddd g}d!||fS )"zC
    Create the source and globs for a __repr__ and return it.
    c                 s  s6   | ].}|j d k	r|j|j dkr"t n|j |jfV  qdS )FTN)r.   r   r1   r   r   r   r   r     s   
z$_make_repr_script.<locals>.<genexpr>c                 S  s$   i | ]\}}}|t kr|d  |qS )_repr)r.   )r   r   rr   r   r   r   r    s      z%_make_repr_script.<locals>.<dictcomp>r
   r  r   r  zgetattr(self, "z", NOTHING)z	%s={%s!r}z%s={%s_repr(%s)}r   Nz1{self.__class__.__qualname__.rsplit(">.", 1)[-1]}z.{self.__class__.__name__}zdef __repr__(self):z  try:z:    already_repring = _compat.repr_context.already_repringz  except AttributeError:z!    already_repring = {id(self),}z:    _compat.repr_context.already_repring = already_repringz  else:z#    if id(self) in already_repring:z      return '...'z	    else:z#      already_repring.add(id(self))z    return f'(z)'z
  finally:z$    already_repring.remove(id(self))r   )rB   r
   r  r   r.   r   r   )rl   r3  Zattr_names_with_reprsrM   Zattribute_fragmentsr   r  rd   accessorfragmentZrepr_fragmentZcls_name_fragmentr   r   r   r   r2    sN    
r2  c                 C  s>   |dkr| j }t||\}}t||t| dd |d | _| S )z%
    Add a repr method to *cls*.
    Nr   r  )r{   r2  rU   r   r   )rx   r3  rl   rL   rM   r   r   r   	_add_repr  s      
r  c                 C  sv   t | }|dkr&t| ts&d}t|t| dd}|dkrr|dk	r`t|dd}|dk	r`|| _|S | d}t||S )aG  
    Return the tuple of *attrs* attributes for a class.

    The tuple also allows accessing the fields by their names (see below for
    examples).

    Args:
        cls (type): Class to introspect.

    Raises:
        TypeError: If *cls* is not a class.

        attrs.exceptions.NotAnAttrsClassError:
            If *cls* is not an *attrs* class.

    Returns:
        tuple (with name accessors) of `attrs.Attribute`

    .. versionchanged:: 16.2.0 Returned tuple allows accessing the fields
       by name.
    .. versionchanged:: 23.1.0 Add support for generic classes.
    NPassed object must be a class.r{   ! is not an attrs-decorated class.)r   r@   r*   r<   r   r{   r   )rx   Zgeneric_baserG   rl   r   r   r   r   ,  s    
r   c                 C  sJ   t | tsd}t|t| dd}|dkr<| d}t|dd |D S )a  
    Return an ordered dictionary of *attrs* attributes for a class, whose keys
    are the attribute names.

    Args:
        cls (type): Class to introspect.

    Raises:
        TypeError: If *cls* is not a class.

        attrs.exceptions.NotAnAttrsClassError:
            If *cls* is not an *attrs* class.

    Returns:
        dict[str, attrs.Attribute]: Dict of attribute name to definition

    .. versionadded:: 18.1.0
    r  r{   Nr  c                 S  s   i | ]}|j |qS r   r   r   r   r   r   r  t  s      zfields_dict.<locals>.<dictcomp>)r@   r*   r<   r   r   )rx   rG   rl   r   r   r   fields_dictZ  s    

r  c                 C  sD   t jdkrdS t| jD ]&}|j}|dk	r|| |t| |j qdS )z
    Validate all attributes on *inst* that have a validator.

    Leaves all exceptions through.

    Args:
        inst: Instance of a class with *attrs* attributes.
    FN)r   Z_run_validatorsr   r   r-   r   r   )r   r   r  r   r   r   r   w  s    	
r   c                 C  s   | | }|od|jkS )z>
    Check if the attribute name comes from a slot class.
    r  )r   rw   )Za_namer   rx   r   r   r   _is_slot_attr  s    
r  ztuple[str, dict, dict]c                 C  s  |
d k	o|
t jk	}|r&|r&d}t||p,|}g }i }|D ]b}|jsP|jtkrPq:|| |||j< |jd k	r|dkrd}t|d}q:|r:|jt jk	r:d}q:t	|||||||||	|||rdnd\}}}| j
tjkr|tj| j
 j |t|d |r
tj|d< |||fS )Nz$Frozen classes can't use on_setattr.TrT  r   )r   	attr_dictr   )r   rg  r=   r1   r,   r   r   r   r9   _attrs_to_init_scriptr!   sysmodulesr   rw   r   r   )rx   rl   pre_initpre_init_has_args	post_initr   r   r   r   r   Zcls_on_setattrrG  has_cls_on_setattrrG   needs_cached_setattrZfiltered_attrsr  r   rL   rM   r   r   r   r   rM    sP    





rM  ri   	value_varhas_on_setattrrP   c                 C  s   d|  d| dS )zJ
    Use the cached object.setattr to set *attr_name* to *value_var*.
    
_setattr('r  r  r   ri   r  r  r   r   r   _setattr  s    r  	Converterri   r  r  r2   rP   c                 C  s   d|  d| | | dS )zk
    Use the cached object.setattr to set *attr_name* to *value_var*, but run
    its converter first.
    r  r  r  )_fmt_converter_callri   r  r  r2   r   r   r   _setattr_with_converter  s    r  )ri   r   r  rP   c                 C  s    |rt | |dS d|  d| S )zo
    Unless *attr_name* has an on_setattr hook, use normal assignment. Otherwise
    relegate to _setattr.
    Tr  r  )r  )ri   r   r  r   r   r   _assign  s    r  c                 C  s*   |rt | |d|S d|  d|| | S )z
    Unless *attr_name* has an on_setattr hook, use normal assignment after
    conversion. Otherwise relegate to _setattr_with_converter.
    Tr  r  )r  r  r  r   r   r   _assign_with_converter  s    r  ro   )r   r   r   c                   s`   | dkrV|dkrdt tfS ddddd fdd}dddddd	 fd
d}d||fS dttfS )zg
    Determine the correct setter functions based on whether a class is frozen
    and/or slotted.
    Tr   rJ   r   r  c                   s&   t |  rt| ||S d|  d| S N_inst_dict['z'] = )r  r  r  r   r   r   
fmt_setter  s    
z&_determine_setters.<locals>.fmt_setterr  r  c                   s4   |st |  rt| |||S d|  d|| | S r  )r  r  r  r  r  r   r   fmt_setter_with_converter  s       z5_determine_setters.<locals>.fmt_setter_with_converter)z_inst_dict = self.__dict__)r  r  r  r  )r   r   r   r  r  r   r  r   _determine_setters  s    
r  )rl   r|  
is_slottedcall_pre_initr  call_post_initdoes_cache_hashr   r   r  r  method_namerP   c           $   
   C  s  |r
dgng }|	r| d t|||\}}}|| g }g }g }i }ddi}| D ]}|jrj| | |j}|jdk	p|jtjk	o|
}|j}t	|j
t}|r|j
jrdnd}|jdk	rt	|jtst|j}n|j}|jdkr|r`t|jf }|dk	r4| |||d| d	 || |j|||j< n| |||d| d	 | |j
j||< nT|dk	r| ||d
| d|| |j|||j< n| ||d
| d| n|j
tk	r@|s@| d| d}|jr| | n
| | |dk	r*| ||||| |j|||j< n| |||| nb|r@| d}|jrd| | n
| | | d| d t|jf }|dk	r| d|||||  | d | d|||d | d	 ||  |j|||j< nB| d||||  | d | d|||d | d	 |  |j
j||< nb|jrT| | n
| | |dk	r| ||||| |j|||j< n| |||| |jdkrT|jdk	r|dkr|j||< qT|dk	rT|jrT|j||< qT|rRt|d< | d |D ]L}d|j }d|j }| d| d| d|j d	 |j||< |||< q|rb| d |r|r|rdt d}ndt d}ndt d}| | |rd d!d" | D } | d#|  d	 d$|}|}!|r@||rd$nd d%d$| 7 }d$d&d' d(d" |D D }"|!|!r2d$nd7 }!|!|"7 }!|r\|r\d)|! d	|d*< d+}#d,| d| d-|r~|#|nd. d/||fS )0z
    Return a script of an initializer for *attrs*, a dict of globals, and
    annotations for the initializer.

    The globals are required by the generated script.
    zself.__attrs_pre_init__()z$_setattr = _cached_setattr_get(self)rP   Nr   rI   Fr  r  zattr_dict['z
'].defaultz=attr_dict['z=NOTHINGzif z is not NOTHING:r  zelse:Tr   z#if _config._run_validators is True:Z__attr_validator_Z__attr_z(self, z, self.zself.__attrs_post_init__()r  z', None)r  z	'] = Noner  z = Noner  c                 s  s    | ]}|j rd |j V  qdS )r  N)r1   r   r   r   r   r   r   	  s      z(_attrs_to_init_script.<locals>.<genexpr>zBaseException.__init__(self, r   z*, c                 S  s   g | ]}| d | qS )=r   )r   Zkw_arg_namer   r   r   r   	  s   z)_attrs_to_init_script.<locals>.<listcomp>c                 s  s   | ]}| d d V  qdS )r  r   N)split)r   Zkwar   r   r   r   	  s     zself.__attrs_pre_init__(r   z
    zdef z):
    passr   )r   r  r   r-   r   r9   r   rg  r:   r@   r,   r?   
takes_selfr2   r  r1   _INIT_FACTORY_PAT_get_global_namerF   r   r4   r*   _first_param_typer   r   r   )$rl   r|  r  r  r  r  r  r   r   r  r  r  r   Zextra_linesr  r  r   Zkw_only_argsZattrs_to_validateZnames_for_globalsr   r   ri   r  Zarg_nameZhas_factoryZ
maybe_selfr2   Zinit_factory_nameargZval_nameZinit_hash_cachevalsZpre_init_argsZpre_init_kw_only_argsNLr   r   r   r  .  s     





	

	


   


   




   



 



"r  )r   rP   c                 C  s
   |  dS )z
    The default __init__ parameter name for a field.

    This performs private-name adjustment via leading-unscore stripping,
    and is the default value of Attribute.alias if not provided.
    r   )lstripr   r   r   r   r   2	  s    r   c                
   @  s\   e Zd ZdZdZdddZdd Zedd	d
dddZdd Z	dd Z
dd Zdd ZdS )r   a  
    *Read-only* representation of an attribute.

    .. warning::

       You should never instantiate this class yourself.

    The class has *all* arguments of `attr.ib` (except for ``factory`` which is
    only syntactic sugar for ``default=Factory(...)`` plus the following:

    - ``name`` (`str`): The name of the attribute.
    - ``alias`` (`str`): The __init__ parameter name of the attribute, after
      any explicit overrides and default private-attribute-name handling.
    - ``inherited`` (`bool`): Whether or not that attribute has been inherited
      from a base class.
    - ``eq_key`` and ``order_key`` (`typing.Callable` or `None`): The
      callables that are used for comparing and ordering objects by this
      attribute, respectively. These are set by passing a callable to
      `attr.ib`'s ``eq``, ``order``, or ``cmp`` arguments. See also
      :ref:`comparison customization <custom-comparison>`.

    Instances of this class are frequently used for introspection purposes
    like:

    - `fields` returns a tuple of them.
    - Validators get them passed as the first argument.
    - The :ref:`field transformer <transform-fields>` hook receives a list of
      them.
    - The ``alias`` property exposes the __init__ parameter name of the field,
      with any overrides and default private-attribute handling applied.


    .. versionadded:: 20.1.0 *inherited*
    .. versionadded:: 20.1.0 *on_setattr*
    .. versionchanged:: 20.2.0 *inherited* is not taken into account for
        equality checks and hashing anymore.
    .. versionadded:: 21.1.0 *eq_key* and *order_key*
    .. versionadded:: 22.2.0 *alias*

    For the full version history of the fields, see `attr.ib`.
    )r   r,   r-   r.   r5   r6   r7   r8   r0   r1   r3   r*   r2   r4   r}   r9   r:   NFc                 C  s   t ||p
||p|d\}}}}t| }|d| |d| |d| |d| |d| |d| |d| |d	| |d
| |d| |d| |d|	rtt|	nt |d|
 |d| |d| |d| |d| d S )NTr   r,   r-   r.   r5   r6   r7   r8   r0   r1   r2   r3   r*   r4   r}   r9   r:   )r;   r   r   typesMappingProxyTyper   _EMPTY_METADATA_SINGLETON)r   r   r,   r-   r.   r/   r0   r1   r}   r3   r*   r2   r4   r5   r6   r7   r8   r9   r:   bound_setattrr   r   r   r   ~	  s:       















zAttribute.__init__c                 C  s   t d S r'   )r   r   r   r   r   r   	  s    zAttribute.__setattr__rJ   rE   )r   r   c                 C  st   |d kr|j }n|j d k	r.d| d}t|| ||j|j|jd |j|jd|j||j|j	|j
|j|j|j|j|jS )Nz>Type annotation and type argument cannot both be present for 'z'.F)r*   r=   _default
_validatorr.   r0   r1   r3   r2   r4   r5   r6   r7   r8   r9   r:   )rx   r   r   r*   rG   r   r   r   r   	  s2    
zAttribute.from_counting_attrc                 K  s   t  | }||  |S )a
  
        Copy *self* and apply *changes*.

        This works similarly to `attrs.evolve` but that function does not work
        with :class:`attrs.Attribute`.

        It is mainly meant to be used for `transform-fields`.

        .. versionadded:: 20.3.0
        )copy	_setattrsr   )r   r   newr   r   r   r   	  s    
zAttribute.evolvec                   s   t  fdd jD S )(
        Play nice with pickle.
        c                 3  s*   | ]"}|d krt  |nt jV  qdS )r3   N)r   r   r3   r  r   r   r   r   	  s   z)Attribute.__getstate__.<locals>.<genexpr>rB   r  r   r   r   r   r   	  s    zAttribute.__getstate__c                 C  s   |  t| j| dS r  N)r  r;  r  r   r<  r   r   r   r   	  s    zAttribute.__setstate__c                 C  sL   t | }|D ]8\}}|dkr*||| q|||r@tt|nt qd S )Nr3   )r   r   r  r  r   r  )r   Zname_values_pairsr  r   r   r   r   r   r  	  s    
zAttribute._setattrs)
NNNFNNNNNN)N)r    r!   r"   r#   r  r   r   r$  r   r   r   r   r  r   r   r   r   r   =	  s(   ,          
7	r   c                 C  s2   g | ]*}t |td dd dd|dkddt|dqS )NTFr3   )r   r,   r-   r.   r/   r5   r7   r0   r1   r}   r:   )r   r   r   r  r   r   r   r   
  s   r   r  c                 C  s   g | ]}|j d kr|qS r|   r   r   r   r   r   r   
  s     
 c                 C  s    g | ]}|j r|jd kr|qS r|   )r0   r   r   r   r   r   r   
  s      
 c                   @  sj   e Zd ZdZdZedd dD eddddddd	dd	ddd	dd	dd
fZdZdd Z	dd Z
dd ZdS )rE   a  
    Intermediate representation of attributes that uses a counter to preserve
    the order in which the attributes have been defined.

    *Internal* data structure of the attrs library.  Running into is most
    likely the result of a bug like a forgotten `@attr.s` decorator.
    )r  r  r:   r2   r   r5   r6   r0   r1   r4   r3   r9   r7   r8   r.   r*   c                 c  s8   | ]0}t |t|td dd ddddd dd dd dV  qd S )NTFr   r:   r,   r-   r.   r/   r0   r1   r4   r5   r6   r7   r8   r}   r9   )r   r   r   r  r   r   r   r   =
  s$   z_CountingAttr.<genexpr>)	r   r  r.   r5   r7   r0   r1   r9   r:   r3   NTFr  r   c                 C  st   t  jd7  _t j| _|| _|| _|| _|| _|| _|| _|| _	|| _
|| _|| _|| _|	| _|
| _|| _|| _d S r   )rE   cls_counterr   r  r  r2   r.   r5   r6   r7   r8   r0   r1   r3   r*   r4   r9   r:   )r   r,   r-   r.   r/   r0   r1   r2   r3   r*   r4   r5   r6   r7   r8   r9   r:   r   r   r   r   o
  s"    z_CountingAttr.__init__c                 C  s$   | j dkr|| _ nt| j || _ |S )z
        Decorator that adds *meth* to the list of validators.

        Returns *meth* unchanged.

        .. versionadded:: 17.1.0
        N)r  rD   r   r\  r   r   r   r-   
  s    
z_CountingAttr.validatorc                 C  s    | j tk	rtt|dd| _ |S )z
        Decorator that allows to set the default for an attribute.

        Returns *meth* unchanged.

        Raises:
            DefaultAlreadySetError: If default has been set before.

        .. versionadded:: 17.1.0
        T)r  )r  r   r   r?   r  r   r   r   r,   
  s    
z_CountingAttr.default)r    r!   r"   r#   r  rB   r   r{   r  r   r-   r,   r   r   r   r   rE   !
  s6   1%rE   c                   @  s.   e Zd ZdZdZdddZdd Zdd	 Zd
S )r?   a  
    Stores a factory callable.

    If passed as the default value to `attrs.field`, the factory is used to
    generate a new value.

    Args:
        factory (typing.Callable):
            A callable that takes either none or exactly one mandatory
            positional argument depending on *takes_self*.

        takes_self (bool):
            Pass the partially initialized instance that is being initialized
            as a positional argument.

    .. versionadded:: 17.1.0  *takes_self*
    rF   r  Fc                 C  s   || _ || _d S r'   r  )r   rF   r  r   r   r   r   
  s    zFactory.__init__c                   s   t  fdd jD S )r  c                 3  s   | ]}t  |V  qd S r'   r  r  r   r   r   r   
  s     z'Factory.__getstate__.<locals>.<genexpr>r  r   r   r   r   r   
  s    zFactory.__getstate__c                 C  s&   t | j|D ]\}}t| || qdS r  )r;  r  r  )r   r<  r   r   r   r   r   r   
  s    zFactory.__setstate__N)F)r    r!   r"   r#   r  r   r   r   r   r   r   r   r?   
  s
   
r?   c                 C  s(   g | ] }t |td dd dddddd
qS NTF)
r   r,   r-   r.   r/   r5   r7   r0   r1   r}   r   r   r  r   r   r   r   
  s   c                   @  sZ   e Zd ZdZdZdddddZedddd	d
ZddddddZdd Z	dd Z
dS )r  ae  
    Stores a converter callable.

    Allows for the wrapped converter to take additional arguments. The
    arguments are passed in the order they are documented.

    Args:
        converter (Callable): A callable that converts the passed value.

        takes_self (bool):
            Pass the partially initialized instance that is being initialized
            as a positional argument. (default: `False`)

        takes_field (bool):
            Pass the field definition (an :class:`Attribute`) into the
            converter as a positional argument. (default: `False`)

    .. versionadded:: 24.1.0
    )__call__r  Z_global_namer2   takes_fieldr  Fr  r  c                  s   | _ | _| _t|}|  _ js@ js@ fdd _nF jr\ js\ fdd _n* jsx jrx fdd _n fdd _| }|d k	r| jjd< d S )Nc                   s
     | S r'   r2   )r   r   __r   r   r   r     r   z$Converter.__init__.<locals>.<lambda>c                   s     | |S r'   r  )r   instancer  r   r   r   r     s    c                   s     | |S r'   r  )r   r  rQ  r   r   r   r     s    c                   s     | ||S r'   r  )r   r  rQ  r   r   r   r   #  s     rP   )	r2   r  r  r   get_first_param_typer  r  get_return_typerp   )r   r2   r  r  exrtr   r   r   r     s    
zConverter.__init__rJ   )ri   rP   c                 C  s
   d|  S )zh
        Return the name that a converter for an attribute name *attr_name*
        would have.
        Z__attr_converter_r   )ri   r   r   r   r  +  s    zConverter._get_global_name)ri   r  rP   c                 C  s   | j s"| js"| | d| dS | j rJ| jrJ| | d| d| dS | j rf| | d| dS | | d| d| dS )z
        Return a string that calls the converter for an attribute name
        *attr_name* and the value in variable named *value_var* according to
        `self.takes_self` and `self.takes_field`.
        r  r  z, self, attr_dict['z'])z, self)z, attr_dict[')r  r  r  )r   ri   r  r   r   r   r  3  s    zConverter._fmt_converter_callc                 C  s   | j | j| jdS )zx
        Return a dict containing only converter and takes_self -- the rest gets
        computed when loading.
        r2   r  r  r  r   r   r   r   r   D  s    zConverter.__getstate__c                 C  s   | j f | dS )z+
        Load instance from state.
        Nry  r  r   r   r   r   O  s    zConverter.__setstate__N)r    r!   r"   r#   r  r   r%  r  r  r   r   r   r   r   r   r  
  s   	c                 C  s(   g | ] }t |td dd dddddd
qS r  r  r  r   r   r   r   V  s   r  c              	     sV  t d| } t|tr|}n*t|ttfr:dd |D }nd}t||dd}|dd}|dd}	i  |dk	r | |dk	r| d< |dk	r| d< |	dk	r|	 d< t	
| |i  fd	d
}
ttt tdjdd|
_W 5 Q R X |dd}t||d|dd\|d< |d< tf d|i||
}dd | D |_|S )a  
    A quick way to create a new class called *name* with *attrs*.

    .. note::

        ``make_class()`` is a thin wrapper around `attr.s`, not `attrs.define`
        which means that it doesn't come with some of the improved defaults.

        For example, if you want the same ``on_setattr`` behavior as in
        `attrs.define`, you have to pass the hooks yourself: ``make_class(...,
        on_setattr=setters.pipe(setters.convert, setters.validate)``

    .. warning::

        It is *your* duty to ensure that the class name and the attribute names
        are valid identifiers. ``make_class()`` will *not* validate them for
        you.

    Args:
        name (str): The name for the new class.

        attrs (list | dict):
            A list of names or a dictionary of mappings of names to `attr.ib`\
            s / `attrs.field`\ s.

            The order is deduced from the order of the names or attributes
            inside *attrs*.  Otherwise the order of the definition of the
            attributes is used.

        bases (tuple[type, ...]): Classes that the new class will subclass.

        class_body (dict):
            An optional dictionary of class attributes for the new class.

        attributes_arguments: Passed unmodified to `attr.s`.

    Returns:
        type: A new class with *attrs*.

    .. versionadded:: 17.1.0 *bases*
    .. versionchanged:: 18.1.0 If *attrs* is ordered, the order is retained.
    .. versionchanged:: 23.2.0 *class_body*
    .. versionchanged:: 25.2.0 Class names can now be unicode.
    NFKCc                 S  s   i | ]}|t  qS r   )rH   r   r   r   r   r    s      zmake_class.<locals>.<dictcomp>z(attrs argument must be a dict or a list.r   Nr   r   c                   s
   |   S r'   )r   )r3  rh   r   r   r     r   zmake_class.<locals>.<lambda>r	   r    __main__r/   r5   r7   Tr   c                 S  s"   i | ]\}}|j d k	r||j qS r'   )r*   r  r   r   r   r    s    
  )unicodedata	normalizer@   r   rA   rB   r<   popr   r  	new_classr
  r  r  r=   r  	_getframe	f_globalsr   r!   rr  r   r   rp   )r   rl   basesZ
class_bodyZattributes_argumentsr0  rG   r  r  Z	user_inittype_r/   rx   r   r  r   
make_classk  sP    0

 r  )r   r  c                   @  s   e Zd ZdZe Zdd ZdS )_AndValidatorz2
    Compose many validators to a single one.
    c                 C  s   | j D ]}|||| qd S r'   )_validators)r   r   r   r   r  r   r   r   r    s    
z_AndValidator.__call__N)r    r!   r"   r#   rH   r  r  r   r   r   r   r    s   r  c                  G  s6   g }| D ] }| t|tr |jn|g qtt|S )a  
    A validator that composes multiple validators into one.

    When called on a value, it runs all wrapped validators.

    Args:
        validators (~collections.abc.Iterable[typing.Callable]):
            Arbitrary number of validators.

    .. versionadded:: 17.1.0
    )r   r@   r  r  rB   )Z
validatorsr  r-   r   r   r   rD     s    rD   c                    s   t dd  D }|r$ fdd}n fdd} sPtd}|j||d nTt d  }|rn||jd	<  d
 }tst|tr|j	}t|
 }|r||jd< |rt|dddS |S )a  
    A converter that composes multiple converters into one.

    When called on a value, it runs all wrapped converters, returning the
    *last* value.

    Type annotations will be inferred from the wrapped converters', if they
    have any.

        converters (~collections.abc.Iterable[typing.Callable]):
            Arbitrary number of converters.

    .. versionadded:: 20.1.0
    c                 s  s   | ]}t |tV  qd S r'   r@   r  )r   cr   r   r   r   
  s     zpipe.<locals>.<genexpr>c                   s,    D ]"}t |tr|| ||n|| } q| S r'   r	  )rd  r   rQ  r
  
convertersr   r   pipe_converter  s    zpipe.<locals>.pipe_converterc                   s    D ]}|| } q| S r'   r   )rd  r
  r  r   r   r    s    
A)rd  rP   r   rd  rW   rP   Tr  )rp  r   rp   r   r   r  r   r@   r  r  r  )r  Zreturn_instancer  r  tlastr  r   r  r   rC     s&    


rC   )NrI   )N)T)NNNNNNNFFTFFFFFNNFFNNNTN)N)NN)i
__future__r   r  r
  r  r$   r   r!  r\   r  r  r  collections.abcr   r   	functoolsr   typingr   r   r   rI   r
   r   r   r   r   r   r   r   r   
exceptionsr   r   r   r   objectr   r   r  ru   r   r  r  r	  rC   r   r   r   Enumr   r   intr&   rH   rU   ra   rj   rk   rv   ry   r   r   r   r   r   r   r   r   rr  r;   rv  rl   r   rz  r   rD  r  rY  rZ  ra  r  r2  r  r   r  r  rM  r  r  r  r  r  r  r   r   r  Z_arE   r?   _fr  r  r  rD   r   r   r   r   <module>   s2   		

n   #!l4:    N, 
                        
 d
H%8
9
.E
/&   K
	 'd  
k
