o
    tBh"                     @  s  U d Z ddlmZ ddlmZmZmZ ddlmZ ddl	Z
ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl	m*Z* dd	l+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 dd
l2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZF ddlGmHZH h dZIdeJd< dhZKdeJd< ddhZLdeJd< h dZMdeJd< h dZNdeJd< ddhZOdeJd< dZPdeJd< d ZQdeJd!< d"ZRdeJd#< G d$d% d%ZSG d&d' d'ZTd|d,d-ZU	d}d~d2d3ZVdd5d6ZW	7	7ddd:d;ZXdd<d=ZYddAdBZZddEdFZ[d|dGdHZ\ddLdMZ]ddQdRZ^ddWdXZ_dd[d\Z`dd`daZaddddeZbddhdiZcddldmZdddodpZeddqdrZfddudvZgddwdxZhddydzZiG d{dk dkZjdS )z>Plugin for supporting the attrs library (http://www.attrs.org)    )annotations)IterableListcast)FinalN)TypeTranslationErrorexpr_to_unanalyzed_type)	ARG_NAMEDARG_NAMED_OPTARG_OPTARG_POSMDEFArgumentAssignmentStmtCallExprContext	Decorator
ExpressionFuncDefJsonDict
LambdaExprListExpr
MemberExprNameExprOverloadedFuncDefPlaceholderNodeRefExprSymbolTableNodeTempNode	TupleExprTypeInfoTypeVarExprVaris_class_var)SemanticAnalyzerPluginInterface)_get_argument_get_bool_argument_get_decorator_bool_argumentadd_attribute_to_class
add_methoddeserialize_and_fixup_type)make_wildcard_trigger)make_simplified_unionmap_type_from_supertype)AnyTypeCallableTypeFunctionLikeInstanceLiteralTypeNoneType
Overloaded	TupleTypeType	TypeOfAnyTypeVarType	UnionTypeget_proper_type)fill_typevars)unmangle>   attr.s
attr.attrsattr.attributesr   attr_class_makerszattr.dataclassattr_dataclass_makerszattr.frozenzattrs.frozenattr_frozen_makers>   attr.defineattr.mutableattrs.defineattrs.mutableattr_define_makers>   attr.ib	attr.attr
attr.fieldattr.attribattrs.fieldattr_attrib_makerszattr.converters.optionalzattrs.converters.optionalattr_optional_converters_ATSELF_TVAR_NAME__attrs_attrs__MAGIC_ATTR_NAME_AttrsAttributesMAGIC_ATTR_CLS_NAMEc                   @  s   e Zd ZdZd	d
ddZdS )	Converterz/Holds information about a `converter=` argumentN	init_typeType | NonereturnNonec                 C  s
   || _ d S N)rV   )selfrV    r\   i/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/plugins/attrs.py__init__T   s   
zConverter.__init__rZ   )rV   rW   rX   rY   )__name__
__module____qualname____doc__r^   r\   r\   r\   r]   rU   Q   s    rU   c                   @  sF   e Zd ZdZd%ddZd&ddZd'ddZed(dd Zd)d"d#Z	d$S )*	AttributezThe value of an attr.ib() call.namestrinfor    has_defaultboolinitkw_only	converterConverter | Nonecontextr   rV   rW   rX   rY   c	           	      C  s4   || _ || _|| _|| _|| _|| _|| _|| _d S rZ   )rd   rf   rg   ri   rj   rk   rm   rV   )	r[   rd   rf   rg   ri   rj   rk   rm   rV   r\   r\   r]   r^   [   s   
zAttribute.__init__ctxmypy.plugin.ClassDefContextr   c                 C  s  | j sJ d}| jr!| jjr| jj}n|jd| j ttj}n
| jp*| j	| j
 j}d}|du r9d}ttj}nt|}t|trJ|jtjkrJd}|rg|jjjrg| j	| j
 j}|dus^J |jj|| j | jrr| jrotnt}n| jrwtnt}tt| j
d||d|S )z1Return this attribute as an argument to __init__.Nz-Cannot determine __init__ type from converterFT_)ri   rk   rV   apifailrm   r.   r7   
from_errorrf   rd   typeunannotatedr:   
isinstancetype_of_anyoptionsdisallow_untyped_defsnodemsgneed_annotation_for_varrj   rg   r
   r	   r   r   r   r"   lstrip)r[   rn   rV   ru   proper_typerz   arg_kindr\   r\   r]   argumento   s0   


zAttribute.argumentr   c              
   C  s\   | j | j| j| j| jdu| jr| jjr| jj nd| jj| jj	| jr*| j d	S dd	S )z6Serialize this object so it can be saved and restored.N)	rd   rg   ri   rj   has_converterconverter_init_typecontext_linecontext_columnrV   )
rd   rg   ri   rj   rk   rV   	serializerm   linecolumn)r[   r\   r\   r]   r      s    zAttribute.serializedatarq   r$   c                 C  sz   |d }|rt ||nd}|d }|rt ||nd}t|d ||d |d |d |d r0t|ndt|d	 |d
 d|S )z)Return the Attribute that was serialized.rV   Nr   rd   rg   ri   rj   r   r   r   )r   r   )r*   rc   rU   r   )clsrf   r   rq   raw_init_typerV   raw_converter_init_typer   r\   r\   r]   deserialize   s"   zAttribute.deserializesub_typec                 C  s&   | j rt| j || j| _ dS d| _ dS )zoExpands type vars in the context of a subtype when an attribute is inherited
        from a generic super type.N)rV   r-   rf   )r[   r   r\   r\   r]   expand_typevar_from_subtype   s   
z%Attribute.expand_typevar_from_subtypeN)rd   re   rf   r    rg   rh   ri   rh   rj   rh   rk   rl   rm   r   rV   rW   rX   rY   )rn   ro   rX   r   )rX   r   )rf   r    r   r   rq   r$   rX   rc   )r   r    rX   rY   )
r_   r`   ra   rb   r^   r   r   classmethodr   r   r\   r\   r\   r]   rc   X   s    


*rc   rn   ro   rX   rh   c                 C  s   t | d}t | d}t | d}|dur%t|du|dufr%| jd| j |dur+|S |du r1d}|du r7|}|du rG|du rG| jd| j |S )	zh
    Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
    value of order.
    cmpeqorderNz%Don't mix "cmp" with "eq" and "order"TFz eq must be True if order is True)%_get_decorator_optional_bool_argumentanyrq   rr   reason)rn   r   r   r   r\   r\   r]   _determine_eq_order   s   


r   rd   re   defaultbool | Nonec                 C  st   t | jtr8t| j|}|r6t |tr(|jdkrdS |jdkr!dS |jdkr(dS | jd| d| j |S |S |S )	zqReturn the Optional[bool] argument for the decorator.

    This handles both @decorator(...) and @decorator.
    zbuiltins.TrueTzbuiltins.FalseFzbuiltins.NoneN"z!" argument must be True or False.)rv   r   r   r%   r   fullnamerq   rr   )rn   rd   r   
attr_valuer\   r\   r]   r      s   



r   rY   c                 C  s   i | j jjd< dS )zRecord that we have an attrs class in the main semantic analysis pass.

    The later pass implemented by attr_class_maker_callback will use this
    to detect attrs lasses in base classes.
    	attrs_tagN)r   rf   metadata)rn   r\   r\   r]   attr_tag_callback   s   r   Fauto_attribs_defaultfrozen_defaultc                   s`  | j j t| dd}t| |}t| }t| dd}t| d|}t| dd}t| dd}	| j jjdd	 D ]}
d
|
jv rCd|
jvrC dS q4t| ||}|D ]} 	|j
}|du r_t   dS qLt|  fdd|D  |rst| | |	r| jjjdd dkrt| | dd |D |d| j jjd< t| }|rt| || |rt| | |rt| | dS )a  Add necessary dunder methods to classes decorated with attr.s.

    attrs is a package that lets you define classes without writing dull boilerplate code.

    At a quick glance, the decorator searches the class body for assignments of `attr.ib`s (or
    annotated variables if auto_attribs=True), then depending on how the decorator is called,
    it will add an __init__ or all the compare methods.
    For frozen=True it will turn the attrs into properties.

    See http://www.attrs.org/en/stable/how-does-it-work.html for information on how attrs works.

    If this returns False, some required metadata was not ready yet and we need another
    pass.
    ri   TslotsFauto_attribsrj   
match_args   r   attrsNc                   s   g | ]}|j  |j  jfqS r\   rd   rt   .0attrrf   r\   r]   
<listcomp>8  s    z-attr_class_maker_callback.<locals>.<listcomp>   )   
   c                 S  s   g | ]}|  qS r\   )r   r   r\   r\   r]   r   B  s    
attributesfrozen)r   rf   r'   _get_frozenr   r   mror   _analyze_classgetrd   _add_empty_metadata_add_attrs_magic_attribute
_add_slotsrq   rx   python_version_add_match_argsMethodAdder	_add_init
_add_order_make_frozen)rn   r   r   ri   r   r   r   r   rj   r   
super_infor   r   rz   adderr\   r   r]   attr_class_maker_callback
  sF   




r   c                 C  sJ   t | d|rdS | jjjdd D ]}d|jv r"|jd d r" dS qdS )z$Return whether this class is frozen.r   Tr   r   r   F)r'   r   rf   r   r   )rn   r   r   r\   r\   r]   r   Q  s   r   r   rj   list[Attribute]c                 C  s  i }|du r
t | }| jjjD ],}t|tr1t| |||D ]}|s*|j|v r*||j= |||j< qqt|tr;t	|| q|
 D ]#}|j| jjjv rc| jjj|j j}t|trYq@t|ts`J d|_q@t|}g }	| jjjdd D ]:}
d|
jv r| jt|
j |
jd d D ]"}|d |vrt|
|| j}|| jj |	| ||j qqs|	t|
  }d}t|D ])\}}|jsq|j rq|t!|	kr|j"n| j}|j#s|r| j$d| ||j#O }q|S )	aI  Analyze the class body of an attr maker, its parents, and return the Attributes found.

    auto_attribs=True means we'll generate attributes from type annotations also.
    auto_attribs=None means we'll detect which mode to use.
    kw_only=True means that all attributes created here will be keyword only args in __init__.
    NFr   r   r   r   rd   z<Non-default attributes not allowed after default attributes.)%_detect_auto_attribsr   defsbodyrv   r   _attributes_from_assignmentrd   r   _cleanup_decoratorvaluesrf   namesrz   r   r"   is_initialized_in_classsetr   r   rq   add_plugin_dependencyr+   r   rc   r   r   appendaddlist	enumerateri   rj   lenrm   rg   rr   )rn   r   rj   	own_attrsstmtr   	attributerz   taken_attr_namessuper_attrsr   r   ar   last_defaultirm   r\   r\   r]   r   \  sZ   	






r   rf   r    c                 C  s   g dd| j d< dS )zEAdd empty metadata to mark that we've finished processing this class.Fr   r   N)r   r   r\   r\   r]   r     s   r   c                 C  s   | j jjD ]@}t|trE|jD ]5}t||\}}t|t|kr!qt||D ]\}}t|t	rCt|j
trC|j
jtv rC|jsC   dS q&qqdS )zyReturn whether auto_attribs should be enabled or disabled.

    It's disabled if there are any unannotated attribs()
    FT)r   r   r   rv   r   lvalues_parse_assignmentsr   zipr   calleer   r   rM   
new_syntax)rn   r   lvaluer   rvalueslhsrvaluer\   r\   r]   r     s&   



r   r   r   Iterable[Attribute]c           
   	   c  s    |j D ]Q}t||\}}t|t|krqt||D ]9\}}t|tr?t|jtr?|jjt	v r?t
| |||||}	|	r>|	V  q|rT|jrT|jrTt|sTt| ||||V  qqdS )a!  Return Attribute objects that are created by this assignment.

    The assignments can look like this:
        x = attr.ib()
        x = y = attr.ib()
        x, y = attr.ib(), attr.ib()
    or if auto_attribs is enabled also like this:
        x: type
        x: type = default_value
    N)r   r   r   r   rv   r   r   r   r   rM   _attribute_from_attrib_makerrt   r   r#   _attribute_from_auto_attrib)
rn   r   r   rj   r   r   r   r   r   r   r\   r\   r]   r     s(   

r   r   attr_mapdict[str, Attribute]c                 C  sx   g }| j D ])}t|tr.t|jtr.|jj|v r.|jdkr$d||jj _|jdv r.|| q|D ]}| j | q1dS )zHandle decorators in class bodies.

    `x.default` will set a default value on x
    `x.validator` and `x.default` will get removed to avoid throwing a type error.
    r   T)r   	validatorN)	
decoratorsrv   r   exprr   rd   rg   r   remove)r   r   	remove_mefunc_decoratordecr\   r\   r]   r     s   




	r   r   r   r   r   c           	   	   C  sN   t |j}t|t }| jjj|}|r|jnd}t	|| jj|d|d||S )z.Return an Attribute for a new type assignment.NT)
r<   rd   rv   r   r   rf   r   r   rt   rc   )	rn   rj   r   r   r   rd   has_rhssymrV   r\   r\   r]   r     s
   
r   r   Attribute | Nonec              	   C  s  |r|j s|jdusJ | jj|j| dS t|jdkr'| jd| dS |j}t	| |dd}|t	| |ddO }t
t|d}t
t|d	}	|rT|	rT| jd
| n|	rXd}t|d}
|
r|szt|
| jj| jj}W n ty}   | jd|
 Y nw | j|}|rt|jtr|jjs||j_d|_t|d}t|d}|r|r| jd| n|r| jd| |}t| |}t|j}t|| jj||||||S )zFReturn an Attribute from the assignment or None if you can't make one.Nr   z Too many names for one attributeri   Trj   Fr   factoryz(Can't pass both "default" and "factory".rt   zInvalid argument to typerk   convertz*Can't pass both "convert" and "converter".z$convert is deprecated, use converter)r   rz   rq   r{   r|   r   r   rr   rt   r&   rh   r%   r   rx   is_stub_filer   	anal_typerv   r"   is_inferred_def_parse_converterr<   rd   rc   r   rf   )rn   r   rj   r   r   r   rV   ri   attr_has_defaultattr_has_factorytype_argun_typerk   r   converter_inford   r\   r\   r]   r     sN   
	




r   converter_exprExpression | Nonerl   c           	      C  s  |sdS t  }t|tr(t|jtr(|jjtv r(|jr(|jd r(|jd }d}nd}d}t|trv|jrvt|jt	rR|jj
rJt|jj
trJ|jj
}n,ttj|_|S t|jtrbt|jrb|jj
}nt|jtrvddlm} ||j| jj}t|trttj|_|S |s| jd| ttj|_|S t|}t|tr|jr|jd |_n7t|trg }|jD ]%}t|j}|sq|dkrt dd	 |j!dd D rq|"|jd  q|rt#||_|r|jrt$%|jt& g|_|S )
z/Return the Converter object from an Expression.Nr   TF)type_object_typezVUnsupported converter, only named functions, types and lambdas are currently supportedr   c                 s  s    | ]}|t kV  qd S rZ   )r   )r   kindr\   r\   r]   	<genexpr>  s    z#_parse_converter.<locals>.<genexpr>)'rU   rv   r   r   r   r   rN   argsrz   r   rt   r0   r.   r7   ru   rV   r   is_valid_overloaded_converterr    mypy.checkmemberr   rq   
named_typer   rr   rs   r:   r/   	arg_typesr4   itemsr   r   	arg_kindsr   r,   r9   
make_unionr3   )	rn   r   r   is_attr_converters_optionalconverter_typer   typesitemnum_arg_typesr\   r\   r]   r   b  sp   







$

r   defnr   c                 C  s   t dd | jD S )Nc                 s  s*    | ]}t |t pt |jjtV  qd S rZ   )rv   r   funcrt   r0   r   r  r\   r\   r]   r    s
    
z0is_valid_overloaded_converter.<locals>.<genexpr>)allr  )r  r\   r\   r]   r    s   r  r   'tuple[list[NameExpr], list[Expression]]c                 C  sz   g }g }t | ttfr-tdd | jD rttt | j}t |jttfr)|jj}||fS t | tr9| g}|jg}||fS )zSConvert a possibly complex assignment expression into lists of lvalues and rvalues.c                 s  s    | ]}t |tV  qd S rZ   )rv   r   r  r\   r\   r]   r    s    z%_parse_assignments.<locals>.<genexpr>)	rv   r   r   r  r  r   r   r   r   )r   r   r   r   r\   r\   r]   r     s   
r   r   r   c                 C  s   | j d}| j d}tt| jjjd t dg |}tt| jjjd t g |}tt	|| jjj
t< ttd||dtg}dD ]}|j|||||d q@dS )	z1Generate all the ordering methods for this class.zbuiltins.boolzbuiltins.object.r   otherN)__lt____le____gt____ge__)	self_typetvd)rq   r  r8   rP   r   rf   r   r!   r   r   r   r   r"   r   r)   )rn   r   	bool_typeobject_typer  self_tvar_exprr  methodr\   r\   r]   r     s   r   r   c                 C  s   |D ]I}|j | jjjv r | jjj|j  j}t|tsJ d|_qt|j | jj|j  j}| jj|_| jjj	 d|j  |_
tt|| jjj|j < d|_qdS )zCTurn all the attributes into properties to simulate frozen classes.Tr  N)rd   r   rf   r   rz   rv   r"   is_propertyrt   r   	_fullnamer   r   )rn   r   r   rz   varr\   r\   r]   r     s   
r   c                 C  s   g }g }|D ]}|j sq|jr|||  q|||  q|| }tdd |D r@|D ]}ttj|j_	ttj|_
q0|d|t  dS )zGGenerate an __init__ method for the attributes and add it to the class.c                 s  s&    | ]}t |jjd dtjkV  qdS )rw   N)getattrvariablert   r7   ru   )r   argr\   r\   r]   r    s
    
z_add_init.<locals>.<genexpr>r^   N)ri   rj   r   r   r  r.   r7   implementation_artifactr%  rt   type_annotationr)   r3   )rn   r   r   pos_argskw_only_argsr   r  r   r\   r\   r]   r     s    
r   r   list[tuple[str, Type | None]]c                   s  t tj  fdd|D }jdjd gp g}jt|d}d|_t	||D ]%\\}}}t
||}d|_t|}	t|	trJ|	j|_tt|dd|j|< q/t|g }
t
tt||
dd	}jj|_d|_jj d
t |_d|_tt|dddjjjt< d S )Nc                   s(   g | ]\}}j d |p gp qS )attr.Attribute)rq   named_type_or_none)r   rp   	attr_typeany_typern   r\   r]   r     s    z._add_attrs_magic_attribute.<locals>.<listcomp>builtins.tupler,  r   T)plugin_generatedfallbackr   r  )r  rz   r2  no_serialize)r.   r7   explicitrq   r  r-  basic_new_typeinforT   is_named_tupler   r"   r!  r:   rv   r1   rt   rf   r   r   r   rR   r5   r   is_classvarr   r"  allow_incompatible_override)rn   r   attributes_typesfallback_typetird   rp   r.  r#  r~   attributes_typer\   r/  r]   r     s2   




r   c                 C  s   dd |D | j j_d S )Nc                 S  s   h | ]}|j qS r\   )rd   r   r\   r\   r]   	<setcomp>3  s    z_add_slots.<locals>.<setcomp>)r   rf   r   )rn   r   r\   r\   r]   r   1  s   r   c                   sh   d| j jjvs| j jjd jr2| jd t fdd|D | jdd}t| j| j d|d d S d S )N__match_args__zbuiltins.strc                   s.   g | ]}|j s|jr jt|j d dqS )r3  )last_known_value)rj   ri   copy_modifiedr2   rd   r   str_typer\   r]   r   =  s    z#_add_match_args.<locals>.<listcomp>r1  r3  )rq   r   rd   typ)r   rf   r   r2  rq   r  r5   r(   )rn   r   r   r\   rC  r]   r   6  s   

r   c                   @  s*   e Zd ZdZdddZ		ddddZdS )r   znHelper to add methods to a TypeInfo.

    ctx: The ClassDefCtx we are using on which we will add methods.
    rn   ro   rX   rY   c                 C  s   || _ t|jj| _d S rZ   )rn   r;   r   rf   r  )r[   rn   r\   r\   r]   r^   O  s   zMethodAdder.__init__Nmethod_namere   r  list[Argument]ret_typer6   r  rW   r  TypeVarType | Nonec                 C  s*   |dur|n| j }t| j||||| dS )zAdd a method: def <method_name>(self, <args>) -> <ret_type>): ... to info.

        self_type: The type to use for the self argument or None to use the inferred self type.
        tvd: If the method is generic these should be the type variables.
        N)r  r)   rn   )r[   rF  r  rH  r  r  r\   r\   r]   r)   S  s   zMethodAdder.add_methodrn   ro   rX   rY   )NN)rF  re   r  rG  rH  r6   r  rW   r  rI  rX   rY   )r_   r`   ra   rb   r^   r)   r\   r\   r\   r]   r   G  s    
	)rn   ro   rX   rh   rZ   )rn   ro   rd   re   r   r   rX   r   rJ  )FF)rn   ro   r   r   r   rh   rX   rh   )rn   ro   r   rh   rX   rh   )rn   ro   r   r   rj   rh   rX   r   )rf   r    rX   rY   )
rn   ro   r   r   r   rh   rj   rh   rX   r   )r   r   r   r   rX   rY   )rn   ro   rj   rh   r   r   r   r   r   r   rX   rc   )rn   ro   r   rh   rj   rh   r   r   r   r   r   r   rX   r   )rn   ro   r   r   rX   rl   )r  r   rX   rh   )r   r   r   r   rX   r  )rn   ro   r   r   rX   rY   )rn   ro   r   r   rX   rY   )rn   ro   r   r   r   r   rX   rY   )rn   ro   r   r+  rX   rY   )krb   
__future__r   typingr   r   r   typing_extensionsr   mypy.pluginmypymypy.exprtotyper   r   
mypy.nodesr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   mypy.plugins.commonr%   r&   r'   r(   r)   r*   mypy.server.triggerr+   mypy.typeopsr,   r-   
mypy.typesr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   mypy.typevarsr;   	mypy.utilr<   r@   __annotations__rA   rB   rG   rM   rN   rP   rR   rT   rU   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r\   r\   r\   r]   <module>   sd    t <
s

G

O


#


C
N




 
"
