o
    7f5                     @  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lGmHZHmIZImJZJ ddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[ ddl\m]Z] ddl^m_Z_ h dZ`dead< dhZbdead< ddhZcdead< h dZddead< h d Zedead!< d"d#hZfdead$< d%Zgdead&< d'Zhdead(< d)Zidead*< d+Zjdead,< G d-d. d.ZkG d/d0 d0Zldd5d6Zm	ddd;d<Zndd>d?Zo	@	@	@dddDdEZpddFdGZqddKdLZrddOdPZsddQdRZtddVdWZudd[d\ZvddadbZwddedfZxddjdkZyddndoZzddrdsZ{ddvdwZ|ddydzZ}dd}d~Z~dddZdddZdddZdddZG ddu du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)get_type_varsmake_simplified_unionmap_type_from_supertype)AnyTypeCallableTypeFunctionLikeInstanceLiteralTypeNoneType
Overloaded
ProperType	TupleTypeType	TypeOfAnyTypeType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)rg   ri   )selfrg   ri    rn   K/home/ertert/spirit/venv/lib/python3.10/site-packages/mypy/plugins/attrs.py__init__a   s   
zConverter.__init__NN)rg   rh   ri   rh   rj   rk   )__name__
__module____qualname____doc__rp   rn   rn   rn   ro   rf   ^   s    rf   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   rg   rh   rj   rk   c
           
      C  s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S rl   )	rw   ry   r{   r|   r~   r   r   r   rg   )
rm   rw   ry   r{   r|   r~   r   r   r   rg   rn   rn   ro   rp   i   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 rn   )id).0binderargrn   rn   ro   
<dictcomp>   s    z&Attribute.argument.<locals>.<dictcomp>z-Cannot determine __init__ type from converterFT_)$r~   r   rg   ri   r8   lenzipr   apifailr   r;   rE   
from_errorr{   rw   typeunannotatedrJ   
isinstancetype_of_anyoptionsdisallow_untyped_defsnodemsgneed_annotation_for_varr   r|   r   r   r   r   ry   lstripr   r.   )rm   r   rg   converter_vars	init_vars	variablesr   proper_typer   arg_kindrw   rn   rn   ro   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)
rw   ry   r|   r~   r   has_converterconverter_init_typecontext_linecontext_columnrg   )rw   ry   r|   r~   r   r   rg   	serializer   linecolumn)rm   rn   rn   ro   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.rg   Nr   rw   ry   r|   r~   r   r   r   r   )r   r   )r6   rv   rf   r   )clsr{   r   r   raw_init_typerg   raw_converter_init_typer   rn   rn   ro   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)rg   r:   r{   )rm   r   rn   rn   ro   expand_typevar_from_subtype   s   
z%Attribute.expand_typevar_from_subtypeN)rw   rx   ry   rz   r{   r,   r|   r}   r~   r}   r   r}   r   r   r   r   rg   rh   rj   rk   )r   r   rj   r   )rj   r    )r{   r,   r   r    r   r0   rj   rv   )r   r,   rj   rk   )
rr   rs   rt   ru   rp   r   r   classmethodr   r   rn   rn   rn   ro   rv   f   s    


4rv   r   r   rj   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   rn   rn   ro   _determine_eq_order   s   


r   rw   rx   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   rw   r   
attr_valuern   rn   ro   r     s$   




r   rk   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   rn   rn   ro   attr_tag_callback"  s   r   Fauto_attribs_defaultfrozen_defaultslots_defaultc                   s  | j j t| dd}t| |}t| }t| d|}t| ddp$t| dd}t| d|}	t| dd}
t| d	d}| j jjd
d D ]}d|jv rOd|jvrO dS q@t| |	|
}|D ]} 	|j
}|du rkt   dS qXt|  fdd|D  |rt| | |r| jjjdd dkrt| | dd |D |d| j jjd< t| }t| |||rdnt |rt| | |rt| | dS |st|  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.
    r~   TslotshashFunsafe_hashauto_attribsr   
match_args   r   attrsNc                   s   g | ]}|j  |j  jfqS rn   )rw   r   r   attrr{   rn   ro   
<listcomp>`  s    z-attr_class_maker_callback.<locals>.<listcomp>   )   
   c                 S  s   g | ]}|  qS rn   )r   r   rn   rn   ro   r   j  s    
attributesfrozenrp   )r   r{   r3   _get_frozenr   r   mror   _analyze_classgetrw   _add_empty_metadata_add_attrs_magic_attribute
_add_slotsr   r   python_version_add_match_argsMethodAdder	_add_initre   
_add_order_make_frozen_remove_hashability)r   r   r   r   r~   r   r   r   hashabler   r   r   
super_infor   r   r   adderrn   r   ro   attr_class_maker_callback,  sP   




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   rn   rn   ro   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   rw   z<Non-default attributes not allowed after default attributes.)%_detect_auto_attribsr   defsbodyr   r   _attributes_from_assignmentrw   r   _cleanup_decoratorvaluesr{   namesr   r&   r.   is_initialized_in_classsetr   r   r   add_plugin_dependencyr7   r   rv   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   rn   rn   ro   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   rn   rn   ro   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rvaluern   rn   ro   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   rn   rn   ro   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$   rw   r|   r   remove)r   r
  	remove_mefunc_decoratordecrn   rn   ro   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)
rL   rw   r   r)   r   r{   r   r   r   rv   )	r   r   r  r  r   rw   has_rhssymrg   rn   rn   ro   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| |}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 converterry   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   rL   rw   rv   r   r{   )r   r   r   r  r  r   rg   r~   attr_has_defaultattr_has_factorytype_argun_typer   r  converter_infory   
alias_exprrw   rn   rn   ro   r  J  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 rl   )r   )r   kindrn   rn   ro   	<genexpr>  s    z#_parse_converter.<locals>.<genexpr>)0rf   r   r   r  r'   r   r^   argsr   r   r   r=   r;   rE   r   rg   r%   is_valid_overloaded_converterr,   mypy.checkmemberr%  r   
named_typer   analyzedr+   baser<   r   typesr   incompatible_typevar_valuer!   r   r   rJ   	arg_typesri   rA   itemsr   r   	arg_kindsr   r9   rI   
make_unionr@   )	r   r#  r!  is_attr_converters_optionalconverter_typer%  r.  itemnum_arg_typesrn   rn   ro   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 rl   )r   r   funcr   r=   r   r6  rn   rn   ro   r'    s
    
z0is_valid_overloaded_converter.<locals>.<genexpr>)allr1  )r8  rn   rn   ro   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 rl   )r   r$   r:  rn   rn   ro   r'  
      z%_parse_assignments.<locals>.<genexpr>)	r   r*   r"   r;  r1  r	   r   r$   r  )r  r   r   r  rn   rn   ro   r     s   
r   r   r   c                 C  s   | j d}| j d}tt| jjjd t dg |ttj	d}t
t| jjjd t g |ttj	}tt|| jjjt< ttd||dtg}dD ]}|j|||||d	 qIdS )
z1Generate all the ordering methods for this class.zbuiltins.boolzbuiltins.object.r   )r   r   upper_boundr   otherN)__lt____le____gt____ge__)	self_typetvd)r   r+  rG   r`   r   r{   r   r;   rE   from_omitted_genericsr-   r(   r   r   r   r.   r   
add_method)r   r   	bool_typeobject_typerF  self_tvar_exprr(  methodrn   rn   ro   r     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.Tr>  N)rw   r   r{   r   r   r   r.   is_propertyrg   r   	_fullnamer(   r   )r   r   r   r   varrn   rn   ro   r   2  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   rE   r   )r   r   rn   rn   ro   r'  c  s
    
z_add_init.<locals>.<genexpr>N)r   r{   r   r~   r   r   r   r|   rw   r   r   r.   is_finalfinal_set_in_initr;  r;   rE   implementation_artifactrS  r   type_annotationrH  r@   )r   r   r   rP  pos_argskw_only_args	sym_tabler   sym_noder(  r   rn   rn   ro   r   H  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   rn   ro   r   w  s    z._add_attrs_magic_attribute.<locals>.<listcomp>builtins.tupler]  r>  r   r   T)plugin_generatedfallback)r   override_allow_incompatibleis_classvar)r;   rE   explicitr   r+  r^  rc   formatr   r   replacebasic_new_typeinfor   r.   rN  rM  rJ   r   r>   r   r{   r(   r   r   r4   rb   rC   )r   r   attributes_typesfallback_type	attr_nametirw   r   r_  rO  r   attributes_typern   r`  ro   r   s  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 rl   )r   )r   prn   rn   ro   r'    r=  z_add_slots.<locals>.<genexpr>r   r   c                 S  s   h | ]}|j qS rn   )rw   r   rn   rn   ro   	<setcomp>  s    z_add_slots.<locals>.<setcomp>c                   s   g | ]} j d qS )builtins.str)r   r+  )r   r   r   rn   ro   r     s    z_add_slots.<locals>.<listcomp>rb  rd  	__slots__r   r   rw   typ)	r   r   r{   r   r   rC   r   r+  r4   )r   r   
slots_typern   r   ro   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__rs  c                   s.   g | ]}|j s|jr jt|j d dqS )rd  )last_known_value)r   r~   copy_modifiedr?   rw   r   str_typern   ro   r     s    z#_add_match_args.<locals>.<listcomp>rb  rd  ru  )r   r{   r   rc  r   r+  rC   r4   )r   r   r   rn   r{  ro   r     s   

r   c                 C  s   t | j| jdt ddd dS )z Remove hashability from a class.__hash__T)rg  overwrite_existingN)r4   r   r   r@   r   rn   rn   ro   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   rj   rk   c                 C  s   || _ t|jj| _d S rl   )r   rK   r   r{   rE  )rm   r   rn   rn   ro   rp     s   zMethodAdder.__init__NrP  rx   r(  list[Argument]ri   rD   rE  rh   rF  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)rE  r5   r   r   r   )rm   rP  r(  ri   rE  rF  rn   rn   ro   rH    s   zMethodAdder.add_methodr   r   rj   rk   rq   )rP  rx   r(  r  ri   rD   rE  rh   rF  r  rj   rk   )rr   rs   rt   ru   rp   rH  rn   rn   rn   ro   r     s    
	rv  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.
    Nrp   )	r   r   rb   rc  
get_methodre   r   r   r<   )rv  
magic_attrinit_methodrn   rn   ro   _get_attrs_init_type  s   r  mypy.plugin.FunctionSigContexttrD   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   rG   r   r   )r   r  r  t_namer   pt_namern   rn   ro   _fail_not_attrs_class  s   
r  rB   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;   rI   relevant_itemsrJ   _get_expanded_attr_typesrG   r?  r>   r  r  r   r	   r   rx   	arg_namesr0  dictr   )
r   rv  r  r  retr6  
item_types	init_funcfield_namesfield_typesrn   rn   ro   r    s4   





r  r.  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 rn   )r   rJ   r   r   rH   )r   rw   f_typesr.  rn   ro   r   5  s    z _meet_fields.<locals>.<dictcomp>)r   r   r1  r   )r.  field_to_typesfieldsrw   rv  rn   r  ro   _meet_fields,  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  r2  r0  ri   re  rw   )r   r(  r   r   default_signaturerw   r   rJ   get_expression_typer   r   r  r  r<   keysr   r   r   re  )r   inst_arg	inst_typeinst_type_str
attr_typesr  rn   rn   ro   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)r0  ri   )r   r(  r  rJ   r   r  r   r;   rF   r6  r0  rG   r?  r>   r   r<   type_objectrb   r   rz  )r   r   r   r0  innerri   rn   rn   ro   fields_function_sig_callback_  s2    




r  )r   r   rj   r}   rl   )r   r   rw   rx   r   r   rj   r   r  )FFF)
r   r   r   r   r   r}   r   r}   rj   r}   )r   r   r   r}   rj   r}   )r   r   r   r   r   r}   rj   r   )r{   r,   rj   rk   )
r   r   r   r   r   r}   r   r}   rj   r  )r   r   r
  r  rj   rk   )r   r   r   r}   r  r$   r  r   r   r   rj   rv   )r   r   r   r}   r   r}   r  r$   r  r   r   r   rj   r  )r   r   r#  r$  rj   r   )r8  r%   rj   r}   )r  r   r   r   rj   r<  )r   r   r   r   rj   rk   )r   r   r   r   rj   rk   )
r   r   r   r   r   r   rP  rQ  rj   rk   )r   r   r   r\  rj   rk   )rv  r>   rj   r  )r   r  r  rD   r  rD   rj   rk   )
r   r  rv  rB   r  rB   r  rB   rj   r  )r.  r  rj   r  )r   r  rj   r<   )ru   
__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.typeopsr8   r9   r:   
mypy.typesr;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   mypy.typevarsrK   	mypy.utilrL   rP   __annotations__rQ   rR   rW   r]   r^   r`   rb   rc   re   rf   rv   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  r  rn   rn   rn   ro   <module>   s    | H 


P

O


$


N
d




+
'





*
 