o
    2gǵ                     @  s  U d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlZddlmZ dd	lmZ dd
lmZmZ ddlmZmZ ddlmZ ddl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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddlm=Z= ddl>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZF ddlGmHZH ddlImJZJmKZKmLZL ddlMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^ ddl_m`Z` ddlambZb h dZcdedd< dhZededd< ddhZfdedd< h dZgdedd < h d!Zhdedd"< d#d$hZidedd%< d&Zjdedd'< d(Zkdedd)< d*Zldedd+< d,Zmdedd-< G d.d/ d/ZnG d0d1 d1Zodd6d7Zp	ddd<d=Zqdd?d@Zr	A	A	AdddEdFZsddGdHZtddIdJZuddNdOZvddRdSZwddTdUZxddYdZZydd^d_ZzddddeZ{ddhdiZ|ddmdnZ}ddqdrZ~ddudvZddydzZdd|d}ZdddZdddZdddZdddZdddZG ddx dxZdddZdddZdddZdddZdddZdddZdS )z>Plugin for supporting the attrs library (http://www.attrs.org)    )annotations)defaultdict)reduce)FinalIterableListMappingcast)LiteralN)apply_generic_arguments)LITERAL_REQ)expand_typeexpand_type_by_instance)TypeTranslationErrorexpr_to_unanalyzed_type)
meet_types)format_type_bare)	ARG_NAMEDARG_NAMED_OPTARG_OPTARG_POSMDEFArgumentAssignmentStmtCallExprContext	Decorator
ExpressionFuncDef	IndexExprJsonDict
LambdaExprListExpr
MemberExprNameExprOverloadedFuncDefPlaceholderNodeRefExprSymbolTableNodeTempNode	TupleExprTypeApplicationTypeInfoTypeVarExprVaris_class_var)SemanticAnalyzerPluginInterface)_get_argument_get_bool_argument_get_decorator_bool_argumentadd_attribute_to_classadd_method_to_classdeserialize_and_fixup_type)make_wildcard_trigger)state)get_type_varsmake_simplified_unionmap_type_from_supertype)AnyTypeCallableTypeFunctionLikeInstanceLiteralTypeNoneType
Overloaded
ProperType	TupleTypeType	TypeOfAnyTypeType	TypeVarIdTypeVarTypeUninhabitedType	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_NAMEz__{}_AttrsAttributes__MAGIC_ATTR_CLS_NAME_TEMPLATE__attrs_init__ATTRS_INIT_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ret_typereturnNonec                 C  s   || _ || _d S N)ri   rk   )selfri   rk    rp   J/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/plugins/attrs.py__init__c   s   
zConverter.__init__NN)ri   rj   rk   rj   rl   rm   )__name__
__module____qualname____doc__rr   rp   rp   rp   rq   rh   `   s    rh   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alias
str | Noneinfor,   has_defaultboolinitkw_only	converterConverter | Nonecontextr   ri   rj   rl   rm   c
           
      C  s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S rn   )	ry   r{   r}   r~   r   r   r   r   ri   )
ro   ry   r{   r}   r~   r   r   r   r   ri   rp   rp   rq   rr   k   s   
zAttribute.__init__ctxmypy.plugin.ClassDefContextr   c                 C  sr  | j sJ d}| jrN| jjr@| jj}|r?| jr?| jjr?t| jj}t| j}|r?t|t|kr?dd t||D }t||}n|j	d| j
 ttj}n
| jpW| j| j j}d}|du rfd}ttj}nt|}t|trw|jtjkrwd}|r|jjjr| j| j j}|dusJ |jj|| j
 | jr| jrtnt}	n| jrtnt}	| j p| j!d}
t"t#|
||d|	S )z1Return this attribute as an argument to __init__.Nc                 S  s   i | ]\}}|j |qS rp   id).0binderargrp   rp   rq   
<dictcomp>   s    z&Attribute.argument.<locals>.<dictcomp>z-Cannot determine __init__ type from converterFT_)$r   r   ri   rk   r9   lenzipr   apifailr   r<   rF   
from_errorr}   ry   typeunannotatedrL   
isinstancetype_of_anyoptionsdisallow_untyped_defsnodemsgneed_annotation_for_varr   r~   r   r   r   r   r{   lstripr   r.   )ro   r   ri   converter_vars	init_vars	variablesr   proper_typer   arg_kindry   rp   rp   rq   argument   sD   



zAttribute.argumentr    c                 C  s`   | j | 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)
ry   r{   r~   r   r   has_converterconverter_init_typecontext_linecontext_columnri   )ry   r{   r~   r   r   r   ri   	serializer   linecolumn)ro   rp   rp   rq   r      s"   zAttribute.serializedatar   r0   c                 C  s   |d }|rt ||nd}|d }|rt ||nd}t|d |d ||d |d |d |d	 r3t|ndt|d
 |d d|	S )z)Return the Attribute that was serialized.ri   Nr   ry   r{   r~   r   r   r   r   r   )r   r   )r6   rx   rh   r   )clsr}   r   r   raw_init_typeri   raw_converter_init_typer   rp   rp   rq   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)ri   r;   r}   )ro   r   rp   rp   rq   expand_typevar_from_subtype   s   
z%Attribute.expand_typevar_from_subtypeN)ry   rz   r{   r|   r}   r,   r~   r   r   r   r   r   r   r   r   r   ri   rj   rl   rm   )r   r   rl   r   )rl   r    )r}   r,   r   r    r   r0   rl   rx   )r   r,   rl   rm   )
rt   ru   rv   rw   rr   r   r   classmethodr   r   rp   rp   rp   rq   rx   h   s    


4rx   r   r   rl   r   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anyr   r   reason)r   r   r   r   rp   rp   rq   _determine_eq_order   s   


r   ry   rz   defaultbool | Nonec                 C  sx   t | jtr:t| j|}|r8t |tr(|jdkrdS |jdkr!dS |jdkr(dS | jjd| d| jtd	 |S |S |S )
zqReturn the Optional[bool] argument for the decorator.

    This handles both @decorator(...) and @decorator.
    zbuiltins.TrueTzbuiltins.FalseFzbuiltins.NoneN"z1" argument must be a True, False, or None literalcode)	r   r   r   r1   r$   fullnamer   r   r   )r   ry   r   
attr_valuerp   rp   rq   r     s$   




r   rm   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 classes in base classes.
    	attrs_tagN)r   r}   metadatar   rp   rp   rq   attr_tag_callback$  s   r   Fauto_attribs_defaultfrozen_defaultslots_defaultc                 C  sB   t | jjj t| |||W  d   S 1 sw   Y  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.

    Hashability will be set according to https://www.attrs.org/en/stable/hashing.html.

    See https://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.
    N)r8   strict_optional_setr   r   strict_optionalattr_class_maker_callback_impl)r   r   r   r   rp   rp   rq   attr_class_maker_callback.  s
   $r   c                   s  | j j t| dd}t| |}t| }t| 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| }t| |||rdnt |rt| | |rt| | t| ddot| dd}nt| d}|d u rt| d}t| d}d| j jjv }|s|d u r|du r	 dS |r| j jjd	 jd | j jjd< dS t|  dS )Nr   Tslotsauto_attribsr   F
match_args   r   attrsc                   s   g | ]}|j  |j  jfqS rp   )ry   r   r   attrr}   rp   rq   
<listcomp>m  s    z2attr_class_maker_callback_impl.<locals>.<listcomp>   )   
   c                 S  s   g | ]}|  qS rp   )r   r   rp   rp   rq   r   w  s    
attributesfrozenrr   hashunsafe_hashr   __hash__)r   r}   r3   _get_frozenr   r   mror   _analyze_classgetry   _add_empty_metadata_add_attrs_magic_attribute
_add_slotsr   r   python_version_add_match_argsMethodAdder	_add_initrg   
_add_order_make_frozennames_remove_hashability)r   r   r   r   r   r   r   r   r   r   r   
super_infor   r   r   adderhashabler   has_own_hashrp   r   rq   r   L  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)r3   r   r}   r   r   )r   r   r   rp   rp   rq   r     s   r   r   r   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   ry   z<Non-default attributes not allowed after default attributes.)%_detect_auto_attribsr   defsbodyr   r   _attributes_from_assignmentry   r   _cleanup_decoratorvaluesr}   r   r   r&   r.   is_initialized_in_classsetr   r   r   add_plugin_dependencyr7   r   rx   r   r   appendaddlist	enumerater   r   r   r   r~   r   )r   r   r   	own_attrsstmtr   	attributer   taken_attr_namessuper_attrsr   r   ar   last_defaultir   rp   rp   rq   r     sZ   	






r   r}   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   rp   rp   rq   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   r   r   lvalues_parse_assignmentsr   r   r   calleer'   r   r_   
new_syntax)r   r   lvaluer  rvalueslhsrvaluerp   rp   rq   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
        x: type = attr.ib(...)
    N)r  r  r   r   r   r   r	  r'   r   r_   _attribute_from_attrib_makerr   r
  r/   _attribute_from_auto_attrib)
r   r   r   r   r  r  r  r  r  r   rp   rp   rq   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)	
decoratorsr   r#   exprr$   ry   r~   r   remove)r   r  	remove_mefunc_decoratordecrp   rp   rq   r   :  s   




	r   r  r$   r  r   c           	   
   C  sP   t |j}t|t }| jjj|}|r|jnd}t	|d| jj|d|d||	S )z.Return an Attribute for a new type assignment.NT)
rN   ry   r   r)   r   r}   r   r   r   rx   )	r   r   r  r  r   ry   has_rhssymri   rp   rp   rq   r  X  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| |}d}t|d}|r| j|}|du r| jjd|td 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 attributer   Tr   Fr   factoryz(Can't pass both "default" and "factory".r   zInvalid argument to typer   convertz*Can't pass both "convert" and "converter".z$convert is deprecated, use converterr{   z8"alias" argument to attrs field must be a string literalr   )r
  r   r   r   r   r   r  r   r   r2   r   r1   r   r   is_stub_filer   	anal_typer   r.   is_inferred_def_parse_converterparse_str_literalr   rN   ry   rx   r   r}   )r   r   r   r  r  r   ri   r   attr_has_defaultattr_has_factorytype_argun_typer   r  converter_infor{   
alias_exprry   rp   rp   rq   r  h  sb   
	





r  converter_exprExpression | Noner   c           	      C  sn  |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rw|jrwt|jt	rR|jj
rJt|jj
trJ|jj
}nhttj|_|S t|jtrbt|jrb|jj
}nPt|jtrvddlm} ||j| jj}n;t|trt|jtrt|jtrt|jjtrddlm} ||jj| jj}t|trt||jj| jjj|}nd}t|t rttj|_|S |s| j!d| ttj"|_|S t#|}t|tr|j$r|j$d |_|s|j%|_%n;t|t&r$g }|j'D ]'}t(|j$}|sq|dkrt)dd	 |j*dd D rq|+|j$d  q|r$t,||_|r5|jr5t-.|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 rn   )r   )r   kindrp   rp   rq   	<genexpr>  s    z#_parse_converter.<locals>.<genexpr>)0rh   r   r   r	  r'   r   r`   argsr   r   r   r>   r<   rF   r   ri   r%   is_valid_overloaded_converterr,   mypy.checkmemberr-  r   
named_typer   analyzedr+   baser=   r   typesr   incompatible_typevar_valuer!   r   r   rL   	arg_typesrk   rB   itemsr   r   	arg_kindsr   r:   rK   
make_unionrA   )	r   r+  r)  is_attr_converters_optionalconverter_typer-  r6  itemnum_arg_typesrp   rp   rq   r#    s   









(
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 rn   )r   r   funcr   r>   r   r>  rp   rp   rq   r/    s
    
z0is_valid_overloaded_converter.<locals>.<genexpr>)allr9  )r@  rp   rp   rq   r1    s   r1  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 rn   )r   r$   rB  rp   rp   rq   r/  (      z%_parse_assignments.<locals>.<genexpr>)	r   r*   r"   rC  r9  r	   r   r$   r  )r  r   r  r  rp   rp   rq   r  !  s   
r  r   r   c           
      C  s   | j d}| j d}| jjj dt }tt|tdddg |tt	j
d}tt|g |tt	j
}tt|| jjjt< dD ]-}| jjj d| }|jt|jj|dd	}ttd
||dtg}	|j||	|||d q>dS )z1Generate all the ordering methods for this class.zbuiltins.boolzbuiltins.object.r    )	namespace)r   r   upper_boundr   )__lt____le____gt____ge__r   otherN)	self_typetvd)r   r3  r   r}   r   rb   rI   rH   r<   rF   from_omitted_genericsr-   r(   r   r   copy_modifiedr   raw_idr   r.   r   
add_method)
r   r   	bool_typeobject_typer   rP  self_tvar_exprmethodrH  r0  rp   rp   rq   r   2  s*   
	r   r   c                 C  s   |D ]C}|j | jjjv r| jjj|j  j}t|tsqd|_qt|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.TrF  N)ry   r   r}   r   r   r   r.   is_propertyri   r   	_fullnamer(   r   )r   r   r  r   varrp   rp   rq   r   P  s   

r   method_name%Literal['__init__', '__attrs_init__']c                 C  s   g }g }| j jj}|D ]3}|jsq|jr|||  n|||  |js>|j|v r>||j j	}t
|tr>|jr>d|_q|| }	tdd |	D r^|	D ]}
ttj|
j_ttj|
_qN|||	t  dS )zGGenerate an __init__ method for the attributes and add it to the class.Tc                 s  s&    | ]}t |jjd dtjkV  qdS )r   N)getattrvariabler   rF   r   )r   r   rp   rp   rq   r/    s
    
z_add_init.<locals>.<genexpr>N)r   r}   r   r   r   r   r   r~   ry   r   r   r.   is_finalfinal_set_in_initrC  r<   rF   implementation_artifactr_  r   type_annotationrT  rA   )r   r   r   r\  pos_argskw_only_args	sym_tabler  sym_noder0  r  rp   rp   rq   r   f  s,   	

r   r   list[tuple[str, Type | None]]c              	     s  t tj  fdd|D }jdjd gp g}tjj	
dd}j||d}t||D ](\\}}}t||}	||	_d|	_t|}
t|
trU|
j|	_tt|	dd	|j|< q7t|g }tt|dd	jjj|< tjjtt||d
jj	 dt ddd d S )Nc                   s(   g | ]\}}j d |p gp qS )attr.Attribute)r   named_type_or_none)r   r   	attr_typeany_typer   rp   rq   r     s    z._add_attrs_magic_attribute.<locals>.<listcomp>builtins.tupleri  rF  r   r   T)plugin_generatedfallback)r   override_allow_incompatibleis_classvar)r<   rF   explicitr   r3  rj  re   formatr   r   replacebasic_new_typeinfor   r.   rZ  rY  rL   r   r?   r   r}   r(   r   r   r4   rd   rD   )r   r   attributes_typesfallback_type	attr_nametiry   r   rk  r[  r   attributes_typerp   rl  rq   r     s8   





r   c                   sr   t dd  jjjdd D rd S dd |D  jj_t fdd|D  jd	d
}t j jd|d d S )Nc                 s  s    | ]}|j d u V  qd S rn   )r   )r   prp   rp   rq   r/    rE  z_add_slots.<locals>.<genexpr>r   r   c                 S  s   h | ]}|j qS rp   )ry   r   rp   rp   rq   	<setcomp>  s    z_add_slots.<locals>.<setcomp>c                   s   g | ]} j d qS )builtins.str)r   r3  )r   r   r   rp   rq   r     s    z_add_slots.<locals>.<listcomp>rn  rp  	__slots__r   r   ry   typ)	r   r   r}   r   r   rD   r   r3  r4   )r   r   
slots_typerp   r   rq   r     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__r  c                   s.   g | ]}|j s|jr jt|j d dqS )rp  )last_known_value)r   r   rR  r@   ry   r   str_typerp   rq   r     s    z#_add_match_args.<locals>.<listcomp>rn  rp  r  )r   r}   r   ro  r   r3  rD   r4   )r   r   r   rp   r  rq   r     s   

r   c                 C  s   t | j| jdt ddd dS )z Remove hashability from a class.r   T)rs  overwrite_existingN)r4   r   r   rA   r   rp   rp   rq   r     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.
    r   r   rl   rm   c                 C  s   || _ t|jj| _d S rn   )r   rM   r   r}   rO  )ro   r   rp   rp   rq   rr     s   zMethodAdder.__init__Nr\  rz   r0  list[Argument]rk   rE   rO  rj   rP  TypeVarType | Nonec                 C  s2   |dur|n| j }t| jj| j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)rO  r5   r   r   r   )ro   r\  r0  rk   rO  rP  rp   rp   rq   rT    s   zMethodAdder.add_methodr   r   rl   rm   rs   )r\  rz   r0  r  rk   rE   rO  rj   rP  r  rl   rm   )rt   ru   rv   rw   rr   rT  rp   rp   rp   rq   r     s    
	r  r?   CallableType | Nonec                 C  sV   | j t}|du s|jsdS | j dp| j t}t|tr&t|j ts(dS |j S )zT
    If `typ` refers to an attrs class, get the type of its initializer method.
    Nrr   )	r   r   rd   ro  
get_methodrg   r   r   r=   )r  
magic_attrinit_methodrp   rp   rq   _get_attrs_init_type   s   r  mypy.plugin.FunctionSigContexttrE   parent_tc                 C  s   t || jj}||u rt|trd| dnd| d}nt || jj}t|tr2d| d| dnd| d| d}| j|| j d S )	Nz,Argument 1 to "evolve" has a variable type "z" not bound to an attrs classz.Argument 1 to "evolve" has incompatible type "z"; expected an attrs classz!Argument 1 to "evolve" has type "z" whose item "z " is not bound to an attrs classz" is not an attrs class)r   r   r   r   rI   r   r   )r   r  r  t_namer   pt_namerp   rp   rq   _fail_not_attrs_class  s   
r  rC   display_typ
parent_typlist[Mapping[str, Type]] | Nonec           
      C  s   t |trdS t |tr1g }| D ]}t|}t| |||}|dur,|dur,||7 }qd}q|S t |tr@t| t|j||S t |trut	|}|du rUt
| || dS t||}ttt |jdd }|jdd }	tt||	gS t
| || dS )a  
    For a given type, determine what attrs classes it can be: for each class, return the field types.
    For generic classes, the field types are expanded.
    If the type contains Any or a non-attrs type, returns None; in the latter case, also reports an error.
    Nr   )r   r<   rK   relevant_itemsrL   _get_expanded_attr_typesrI   rI  r?   r  r  r   r	   r   rz   	arg_namesr8  dictr   )
r   r  r  r  retr>  
item_types	init_funcfield_namesfield_typesrp   rp   rq   r     s4   





r  r6  list[Mapping[str, Type]]Mapping[str, Type]c                   sH   t t} D ]}| D ]\}}|| | qq fdd| D S )zr
    "Meet" the fields of a list of attrs classes, i.e. for each field, its new type will be the lower bound.
    c                   s6   i | ]\}}|t |t  krttt|nt qS rp   )r   rL   r   r   rJ   )r   ry   f_typesr6  rp   rq   r   S  s    z _meet_fields.<locals>.<dictcomp>)r   r   r9  r   )r6  field_to_typesfieldsry   r  rp   r  rq   _meet_fieldsJ  s   
r  r=   c              	   C  s   t | jdkr| jd| jj d| j | jS t | jd dkr$| jS | jd d }t| j|}t	|| jj
}t| |||}|du rH| jS t|}tdg| tgtgt |  |g| || jj| jj d| d	S )
z
    Generate a signature for the 'attr.evolve' function that's specific to the call site
    and dependent on the type of the first argument.
    r   r   z " has unexpected type annotationr   r   Ninstz of )r  r:  r8  rk   rq  ry   )r   r0  r   r   default_signaturery   r   rL   get_expression_typer   r   r  r  r=   keysr   r   r   rq  )r   inst_arg	inst_typeinst_type_str
attr_typesr  rp   rp   rq   evolve_function_sig_callback]  s(   r  c                 C  s   t | jdkst | jd dkr| jS t| j| jd d }t|ts0t|tr3t|j	tr3| jS d}| jj
}t|trOt|j}t|trN|g}|j}n	t|trX| }|durut|jv ru|jt j}|dusmJ | jj||dS | jS )z)Provide the signature for `attrs.fields`.r   r   N)r8  rk   )r   r0  r  rL   r   r  r   r<   rG   r>  r8  rI   rI  r?   r   r=   type_objectrd   r   rR  )r   r   r   r8  innerrk   rp   rp   rq   fields_function_sig_callback}  s2    




r  )r   r   rl   r   rn   )r   r   ry   rz   r   r   rl   r   r  )FFF)
r   r   r   r   r   r   r   r   rl   r   )r   r   r   r   rl   r   )r   r   r   r   r   r   rl   r   )r}   r,   rl   rm   )
r   r   r   r   r   r   r   r   rl   r  )r   r   r  r  rl   rm   )r   r   r   r   r  r$   r  r   r   r   rl   rx   )r   r   r   r   r   r   r  r$   r  r   r   r   rl   r  )r   r   r+  r,  rl   r   )r@  r%   rl   r   )r  r   r   r   rl   rD  )r   r   r   r   rl   rm   )r   r   r   r   rl   rm   )
r   r   r   r   r   r   r\  r]  rl   rm   )r   r   r   rh  rl   rm   )r  r?   rl   r  )r   r  r  rE   r  rE   rl   rm   )
r   r  r  rC   r  rC   r  rC   rl   r  )r6  r  rl   r  )r   r  rl   r=   )rw   
__future__r   collectionsr   	functoolsr   typingr   r   r   r   r	   typing_extensionsr
   mypy.pluginmypymypy.applytyper   mypy.errorcodesr   mypy.expandtyper   r   mypy.exprtotyper   r   	mypy.meetr   mypy.messagesr   
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.   r/   r0   mypy.plugins.commonr1   r2   r3   r4   r5   r6   mypy.server.triggerr7   
mypy.stater8   mypy.typeopsr9   r:   r;   
mypy.typesr<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   mypy.typevarsrM   	mypy.utilrN   rR   __annotations__rS   rT   rY   r_   r`   rb   rd   re   rg   rh   rx   r   r   r   r   r   r   r   r   r   r   r   r  r  r#  r1  r  r   r   r   r   r   r   r   r   r  r  r  r  r  r  rp   rp   rp   rq   <module>   s    | L 



N

O


$


N
d




+
'





*
 