
    *e                       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.          Zk G d/ d0          Zldd5Zm	 ddd:Zndd<Zo	 	 	 dddAZpddBZqddFZrddIZsddJZtddNZuddRZvddWZwddZZxdd^ZyddaZzdddZ{ddgZ|ddiZ}ddlZ~ddoZddpZddqZ G dr df          ZddvZdd{ZddZddZddZdd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                      e Zd ZdZd	d
dZdS )	Converterz/Holds information about a `converter=` argumentN	init_typeType | Noneret_typereturnNonec                "    || _         || _        d S N)ri   rk   )selfri   rk   s      2lib/python3.11/site-packages/mypy/plugins/attrs.py__init__zConverter.__init__a   s    "     NN)ri   rj   rk   rj   rl   rm   )__name__
__module____qualname____doc__rr    rs   rq   rh   rh   ^   s3        99! ! ! ! ! ! !rs   rh   c                  J    e Zd ZdZd dZd!dZd"dZed#d            Z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   ri   rj   rl   rm   c	                v    || _         || _        || _        || _        || _        || _        || _        || _        d S ro   )r|   r~   r   r   r   r   r   ri   )	rp   r|   r~   r   r   r   r   r   ri   s	            rq   rr   zAttribute.__init__i   sA     		&	""rs   ctxmypy.plugin.ClassDefContextr   c                T   | j         sJ d}| j        r| j        j        r| j        j        }|r| j        r| j        j        ryt	          | j        j                  }t	          | j                  }|rJt          |          t          |          k    r*d t          ||          D             }t          ||          }nX|j        	                    d| j
                   t          t          j                  }n| j        p| j        | j                 j        }d}|d}t          t          j                  }n;t%          |          }t'          |t                    r|j        t          j        k    rd}|rQ|j        j        j        r@| j        | j                 j        }|J |j        j                            || j
                   | j        r| j        rt8          nt:          }	n| j        rt<          nt>          }	tA          tC          | j        "                    d          |          |d|	          S )z1Return this attribute as an argument to __init__.Nc                $    i | ]\  }}|j         |S ry   )id).0binderargs      rq   
<dictcomp>z&Attribute.argument.<locals>.<dictcomp>   s-     % % %/:vsFIs% % %rs   z-Cannot determine __init__ type from converterFT_)#r   r   ri   rk   r9   lenzipr   apifailr   r<   rF   
from_errorr~   r|   typeunannotatedrK   
isinstancetype_of_anyoptionsdisallow_untyped_defsnodemsgneed_annotation_for_varr   r   r   r   r   r   r   r/   lstrip)
rp   r   ri   converter_vars	init_vars	variablesr   proper_typer   arg_kinds
             rq   argumentzAttribute.argument}   s#   y!%	> 	D~' : N4	 	F 	FDN4K 	F &34>3J%K%KN -dn = =I% F#n*=*=Y*O*O% %>A.R[>\>\% % %	 %0	9$E$E	Ldl[[[#I$899		C$)DI*>*CIK	 566II))44K+w// '*i.CCC"&K 	D37?@ 	D
 9TY',D###GK//dlCCC< 	@(,(8G}}iHH"&"2?wwH DI,,S119==y$PXYYYrs   r!   c           
        | j         | j        | j        | j        | j        du| j        r*| j        j        r| j        j                                        nd| j        j        | j        j	        | j        r| j                                        ndd	S )z6Serialize this object so it can be saved and restored.N)	r|   r   r   r   has_converterconverter_init_typecontext_linecontext_columnri   )
r|   r   r   r   r   ri   	serializer   linecolumn)rp   s    rq   r   zAttribute.serialize   s     I+I|!^47~$"&.":$4>#;#E#E#G#G#G L-"l17;~O113334
 
 	
rs   datar   r1   c                2   |d         }|rt          ||          nd}|d         }|rt          ||          nd}t          |d         ||d         |d         |d         |d         rt          |          ndt          |d	         |d
                   |          S )z)Return the Attribute that was serialized.ri   Nr   r|   r   r   r   r   r   r   )r   r   )r7   r{   rh   r   )clsr~   r   r   raw_init_typeri   raw_converter_init_typer   s           rq   deserializezAttribute.deserialize   s    
 [)FS].}cBBBY]	"&'<"= '&'>DDD 	 LLO.2?.CMI)***n-d;K6LMMM	
 	
 		
rs   sub_typec                f    | 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~   )rp   r   s     rq   expand_typevar_from_subtypez%Attribute.expand_typevar_from_subtype   s4     > 	"4T^XtyYYDNNN!DNNNrs   N)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   r1   rl   r{   )r   r-   rl   rm   )
ru   rv   rw   rx   rr   r   r   classmethodr   r   ry   rs   rq   r{   r{   f   s        ))# # # #(1Z 1Z 1Z 1Zf
 
 
 
  
 
 
 [
0" " " " " "rs   r{   r   r   rl   r   c                <   t          | d          }t          | d          }t          | d          }|5t          |du|duf          r | j                            d| j                   ||S |d}||}|du r$|du r | 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   s       rq   _determine_eq_orderr      s    
 0U
;
;C	.sD	9	9B1#w??E
3$T0ABCC=szJJJ 
 
z}	U{{u}}7DDDLrs   r|   r}   defaultbool | Nonec                >   t          | j        t                    rt          | j        |          }|rit          |t                    r'|j        dk    rdS |j        dk    rdS |j        dk    rdS | j                            d| d| j        t          	           |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   r2   r%   fullnamer   r   r   )r   r|   r   
attr_values       rq   r   r      s     #*h'' "3:t44
 	*h//  &/994&*::: 5&/994GLLKDKKK
     
 Nrs   rm   c                .    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   s    rq   attr_tag_callbackr     s     *,CGL+&&&rs   Fauto_attribs_defaultfrozen_defaultslots_defaultc                   | 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 rd|j        vr dS t          | ||	          }|D ]0}	                    |j
                  }|t                      dS 1t          | fd|D                        |rt          | |           |
r-| j        j        j        dd         dk    rt#          | |           d |D             |d| j         j        j        d<   t%          |           }t'          | |||rdnt(                     |rt+          | |           |rt-          | |           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 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auto_attribsr   F
match_args   r   attrsNc                B    g | ]}|j         |j                  j        fS ry   )r|   r   )r   attrr~   s     rq   
<listcomp>z-attr_class_maker_callback.<locals>.<listcomp>T  s)    $^$^$^4didi1E%F$^$^$^rs      )   
   c                6    g | ]}|                                 S ry   )r   r   r   s     rq   r   z-attr_class_maker_callback.<locals>.<listcomp>^  s"    ???Dt~~''???rs   
attributesfrozenrr   )r   r~   r4   _get_frozenr   r   mror   _analyze_classgetr|   _add_empty_metadata_add_attrs_magic_attribute
_add_slotsr   r   python_version_add_match_argsMethodAdder	_add_initrf   
_add_order_make_frozen)r   r   r   r   r   r   r   r   r   r   r   
super_infor   r   r   adderr~   s                   @rq   attr_class_maker_callbackr   %  s   ( 7<D'VT::Dn--F$$E(g}EEE8nNbccL*3	5AAG-c<FFJgl&qt,  
*---'AT2T2T55\7;;J   xx	""<  %%%44	  s$^$^$^$^S]$^$^$^___ $3
### )cgo4RaR8GCC 	Z((( @?J???& &CGL'"
 Ec:uD&MjjoNNN 3 &S*%%%4rs   c                    t          | d|          rdS | j        j        j        dd         D ]!}d|j        v r|j        d         d         r dS "dS )z$Return whether this class is frozen.r   Tr   r   r   F)r4   r   r~   r   r   )r   r   r   s      rq   r   r   m  sg    #C>BB tgl&qt,  
j)))j.A'.J8.T)445rs   r   r   list[Attribute]c                L   i }|t          |           }| j        j        j        D ]o}t	          |t
                    r3t          | |||          D ]}|s|j        |v r||j        = |||j        <    Jt	          |t                    rt          ||           p|
                                D ]o}|j        | j        j        j        v rU| j        j        j        |j                 j        }t	          |t                    rQt	          |t                    sJ d|_        pt#          |          }g }	| j        j        j        dd         D ]}
d|
j        v r| j                            t-          |
j                             |
j        d         d         D ]{}|d         |vrot0                              |
|| j                  }|                    | j        j                   |	                    |           |                    |j                   ||	t;          |
                                          z   }d}t=          |          D ]d\  }}|j        s|j         r|tC          |	          k    r|j"        n| j        }|j#        s|r| j        $                    d|           ||j#        z  }e|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   r|   z<Non-default attributes not allowed after default attributes.)%_detect_auto_attribsr   defsbodyr   r   _attributes_from_assignmentr|   r   _cleanup_decoratorvaluesr~   namesr   r'   r/   is_initialized_in_classsetr   r   r   add_plugin_dependencyr8   r   r{   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   s                    rq   r   r   x  s    ')I+C00 ! 0 0dN++ 
	03C|WUU , ,
 $ -	Y(>(>!$),'+	$)$$, i(( 	0tY///%%'' 	1 	1	 >SW\///7<%in5:D$00 dC(((((+0D( 9~~Kgl&qt, 1 1
j)))G))*?
@S*T*TUUU"+G4\B 1 1 <'777!--j$HHA11#',???&&q)))$((000tI$4$4$6$6777J L!*-- . .9~ 	 	 ()C,<,<'<'<)###'$ 	b 	bGLLWY`aaa	--rs   r~   r-   c                     g dd| j         d<   dS )zEAdd empty metadata to mark that we've finished processing this class.Fr   r   N)r   )r~   s    rq   r   r     s    ,.%@@DM'rs   c                   | j         j        j        D ]}t          |t                    r|j        D ]}t          ||          \  }}t          |          t          |          k    r6t          ||          D ]S\  }}t          |t                    r9t          |j
        t                    r|j
        j        t          v r|j        s   dS Td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rvalues          rq   r   r     s    
 ! % %dN++ 	%, % %#5fd#C#C w<<3w<<// #&w#8#8 
% 
%KC #6844%&v}g>>% #M26HHH $ I
  %uuuu
% 4rs   r  r   Iterable[Attribute]c           
   #    K   |j         D ]}t          ||          \  }}t          |          t          |          k    r6t          ||          D ]\  }}t	          |t
                    rHt	          |j        t                    r.|j        j        t          v rt          | |||||          }	|	r|	V  b|r2|j        r+|j        r$t          |          st          | ||||          V  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   r   r   r  r(   r   r^   _attribute_from_attrib_makerr   r  r0   _attribute_from_auto_attrib)
r   r  r   r   r  r  r  r  r  r   s
             rq   r   r     s0      , S S-fd;;w<<3w<<'' w00 	S 	SKC 68,,	Sv}g66	S M*.@@@3CwPSU[]abb JJJ S$) S SUXHYHY S1#wVTRRRRR	SS Srs   r   attr_mapdict[str, Attribute]c                V   g }| j         D ]}t          |t                    rht          |j        t                    rN|j        j        |v r@|j        dk    rd||j        j                 _        |j        dv r|                    |           |D ]}| j                             |           d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%   r|   r   r   remove)r  r  	remove_mefunc_decoratordecs        rq   r   r     s     I/ 1 1~z22	1>.99	1 #(H44"i//AE,12>"&>>>   000 $ $s####$ $rs   r  r%   r  r   c           
         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)
rM   r|   r   r*   r   r~   r   r   r   r{   )	r   r   r  r  r  r|   has_rhssymri   s	            rq   r  r  *  so     CHDVX...G
',

 
 
&
&C)TIT37<$tYWWWrs   r   Attribute | Nonec           
        |r7|j         s0|j        J | j        j                            |j        |           dS t          |j                  dk    r| j                            d|           dS |j        }t          | |dd          }|t          | |dd          z  }t          t          |d                    }t          t          |d	                    }	|r|	r| j                            d
|           n|	rd}t          |d          }
|
r|s	 t          |
| j        j        | j        j                  }| j                            |          }|r9t!          |j        t"                    r|j        j        s||j        _        d|_        n+# t&          $ r | j                            d|
           Y nw xY w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 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 converter)r  r   r   r   r   r   r  r   r   r3   r   r2   r   r   is_stub_file	anal_typer   r/   is_inferred_defr   _parse_converterrM   r|   r{   r   r~   )r   r   r   r  r  r  ri   r   attr_has_defaultattr_has_factorytype_argun_typer   r'  converter_infor|   s                   rq   r  r  :  s     DO x###++CHd;;;t
4<17>>>t 	I c66488D !#vy%@@@G M&)<<==M&)<<==  ,  @&IIII	   VV,,H 
,	 
,		,-hI]^^G ))'22I ,Z#66 ,sx} , )&+# $ 	? 	? 	?GLL3X>>>>>	? fk22IFI..G 9 BFKKKK	 ;VDDD	%c955NCHDcgl,dG^TS\  s   %F %F32F3converter_exprExpression | Noner   c                   |sdS t                      }t          |t                    rQt          |j        t                    r7|j        j        t          v r$|j        r|j        d         r|j        d         }d}nd}d}t          |t                    r|j        rt          |j        t                    rY|j        j
        r-t          |j        j
        t                    r|j        j
        }nit          t          j                  |_        |S t          |j        t                     r"t#          |j                  r|j        j
        }nt          |j        t$                    r!ddlm}  ||j        | j        j                  }nt          |t.                    rt          |j        t2                    rt          |j        t                    rt          |j        j        t$                    riddlm}  ||j        j        | j        j                  }t          |t6                    r,t9          ||j        j        | j        j        j        |          }nd}t          |t@                    r t          t          j                  |_        |S |s;| j        !                    d|           t          t          j"                  |_        |S tG          |          }t          |t6                    r(|j$        r!|j$        d         |_        |s|j%        |_%        nt          |tL                    rg }|j'        D ]f}tQ          |j$                  }|s|dk    r'tS          d |j*        dd         D                       rF|+                    |j$        d                    g|rtY          |          |_        |r3|j        r,t[          j.        |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              3  ,   K   | ]}|t           k    V  d S ro   )r   )r   kinds     rq   	<genexpr>z#_parse_converter.<locals>.<genexpr>  s&      (X(XT(X(X(X(X(X(Xrs   )0rh   r   r   r  r(   r   r_   argsr   r   r   r>   r<   rF   r   ri   r&   is_valid_overloaded_converterr-   mypy.checkmemberr4  r   
named_typer    analyzedr,   baser=   r   typesr   incompatible_typevar_valuer"   r   r   rK   	arg_typesrk   rB   itemsr   r   	arg_kindsr   r:   rJ   
make_unionrA   )	r   r1  r0  is_attr_converters_optionalconverter_typer4  r>  itemnum_arg_typess	            rq   r+  r+  }  s   
  t[[N>8,,,~,g66, !*.FFF G" G (,Q/&*##&+#"&N.'** !"~/B !"n)733 	W"' &J~7J7OQ],^,^ &!/!4!9+293H+I+I(%%+->?? 	WDaE
 E
 	W ,05NN+X66 	W999999--n.A37CUVVN>9--"~.@@" ~*G44" ~*/::	" 	655555)).*=*BCGDVWWnl33 	"4'-6	 NN "N.*-- #*9+@#A#A  	
 	
 	

 $+9+?#@#@ $^44N.,// DN4L D#1#;A#> * 	>&4&=N#	NJ	/	/ D"( 	, 	,D//M  q  S(X(XT^TUTVTVEW(X(X(X%X%X LL*++++ 	D'<U'C'CN$" `~'? ` $-#79QS[S]S]8^#_#_ rs   defnr&   c                >    t          d | j        D                       S )Nc              3     K   | ]9}t          |t                     pt          |j        j        t                    V  :d S ro   )r   r   funcr   r>   r   rF  s     rq   r7  z0is_valid_overloaded_converter.<locals>.<genexpr>  sV         i((	(	TJty~|,T,T     rs   )allrA  )rH  s    rq   r9  r9    s2      J     rs   r  'tuple[list[NameExpr], list[Expression]]c                l   g }g }t          | t          t          f          rqt          d | j        D                       r%t          t          t                   | j                  }t          |j        t          t          f          r|j        j        }n t          | t                    r| g}|j        g}||fS )zSConvert a possibly complex assignment expression into lists of lvalues and rvalues.c              3  @   K   | ]}t          |t                    V  d S ro   )r   r%   rL  s     rq   r7  z%_parse_assignments.<locals>.<genexpr>  s,      CCdz$))CCCCCCrs   )	r   r+   r#   rM  rA  r
   r   r%   r  )r  r  r  r  s       rq   r  r    s     !G "G&9h/00  CCflCCCCC 	94>6<88GdkIx#899 	(k'G	FH	%	%  (;-Grs   r   r   c           
     x   | j                             d          }| j                             d          }t          t          | j        j        j        dz   t          z   dg |t          t          j	                            }t          t          | j        j        j        dz   t          z   g |t          t          j	                            }t          t          |          | j        j        j        t          <   t          t          d|          |dt                     g}dD ]}|                    |||||	           d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;  rH   ra   r   r~   r   r<   rF   from_omitted_genericsr.   r)   r   r   r   r/   r   
add_method)r   r   	bool_typeobject_typerZ  self_tvar_exprr8  methods           rq   r   r     s)   ""?33I'$$%677K
 #n4	788  C !#n4
	/00 N *9~)N)NCGL~&S#&&T7;;<D: J JyCSIIIIJ Jrs   r   c                   |D ]}|j         | j        j        j        v r?| j        j        j        |j                  j        }t          |t                    sQd|_        Yt          |j         |j                  }| j        j        |_        | j        j        j	         d|j          |_
        t          t          |          | j        j        j        |j         <   d|_        dS )zCTurn all the attributes into properties to simulate frozen classes.TrR  N)r|   r   r~   r   r   r   r/   is_propertyri   r   	_fullnamer)   r   )r   r   r  r   vars        rq   r   r     s     # #	>SW\///7<%in5:DdC((  #D ini&9::Cw|CH"w|4AAsxAACM+:4+E+ECGLsx("COO## #rs   method_name%Literal['__init__', '__attrs_init__']c                   g }g }| j         j        j        }|D ]}|j        s
|j        r)|                    |                    |                      n(|                    |                    |                      |j        s>|j        |v r5||j                 j	        }t          |t                    r|j        rd|_        ||z   }	t          d |	D                       rF|	D ]C}
t          t           j                  |
j        _        t          t           j                  |
_        D|                    ||	t-                                 dS )zGGenerate an __init__ method for the attributes and add it to the class.Tc              3  h   K   | ]-}t          |j        j        d d          t          j        k    V  .dS )r   N)getattrvariabler   rF   r   )r   r   s     rq   r7  z_add_init.<locals>.<genexpr>H  sQ        
  	!=$779;PP	     rs   N)r   r~   r   r   r   r   r   r   r|   r   r   r/   is_finalfinal_set_in_initrM  r<   rF   implementation_artifactrj  r   type_annotationr\  rA   )r   r   r   re  pos_argskw_only_args	sym_tabler  sym_noder8  r  s              rq   r   r   -  sm    HL"I 2 2	~ 	 	5	 2 23 7 78888OOI..s33444 $ 	29)D)D 05H(C(( 2X-> 2-1*l"D
  
      K  	K 	KA%i&GHHAJO '	(I J JA	[$

33333rs   r   list[tuple[str, Type | None]]c           	         t          t          j                   fd|D             } j                            d j                            dg          pg          }t                               j        j	        
                    dd                    } j                            ||d          }t          ||          D ]u\  \  }}}t          ||          }	||	_        d|	_        t!          |          }
t#          |
t$                    r|
j        |	_        t+          t,          |	d          |j        |<   vt%          |g           }t+          t,          |d           j        j        j        |<   t1           j         j        t2          t5          ||	           j        j	         dt2           dd
           d S )Nc                V    g | ]%\  }}j                             d |pg          p&S )attr.Attribute)r   named_type_or_none)r   r   	attr_typeany_typer   s      rq   r   z._add_attrs_magic_attribute.<locals>.<listcomp>\  sN     $ $ $Ay 	""#3i6K85LMMYQY$ $ $rs   builtins.tuplerv  rR  r   r   T)plugin_generatedfallback)r   override_allow_incompatibleis_classvar)r<   rF   explicitr   r;  rw  rd   formatr   r   replacebasic_new_typeinfor   r/   rc  rb  rK   r   r?   r   r~   r)   r   r   r5   rc   rD   )r   r   attributes_typesfallback_type	attr_nametir|   r   rx  rd  r   attributes_typery  s   `           @rq   r   r   X  s    y)**H$ $ $ $ $!$ $ $ G&&37556F
SS_W_` M -33CG4D4L4LSRU4V4VWWI		#	#I}a	@	@B #E+; < < K K	q9$	""%i00k8,, 	("'CH(sTJJJr2&&O %4D"t$T$T$TCGLy!"_===G$8888$(     rs   c                F    t          d  j        j        j        dd         D                       rd S d |D              j        j        _        t           fd|D              j                            d                    }t           j         j        d|	           d S )
Nc              3  (   K   | ]}|j         d u V  d S ro   )r   )r   ps     rq   r7  z_add_slots.<locals>.<genexpr>  s(      
;
;q17d?
;
;
;
;
;
;rs   r   r   c                    h | ]	}|j         
S ry   )r|   r   s     rq   	<setcomp>z_add_slots.<locals>.<setcomp>  s    ;;;$);;;rs   c                D    g | ]}j                             d           S )builtins.str)r   r;  )r   r   r   s     rq   r   z_add_slots.<locals>.<listcomp>  s)    @@@		N	+	+@@@rs   rz  r|  	__slots__r   r   r|   typ)	r   r   r~   r   r   rD   r   r;  r5   )r   r   
slots_types   `  rq   r   r     s    

;
;CGL$4QrT$:
;
;
;;;  	 <;
;;;CGL @@@@Z@@@##$455  J swCG+:VVVVVVrs   c                B   d| j         j        j        vs| j         j        j        d         j        rn| j                            d          t          fd|D             | j                            d                    }t          | j        | j         d|           d S d S )N__match_args__r  c                    g | ]:}|j         	|j                            t          |j                             ;S )r|  )last_known_value)r   r   copy_modifiedr@   r|   )r   r   str_types     rq   r   z#_add_match_args.<locals>.<listcomp>  s^       | )-	&&DIX`8a8a8a&bb  rs   rz  r|  r  )r   r~   r   r{  r   r;  rD   r5   )r   r   r   r  s      @rq   r   r     s     2227<./@ 	3 7%%n55   &  
 W''(899
 
 

 	37>NT^______ 	32rs   c                  (    e Zd ZdZddZ	 	 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                P    || _         t          |j        j                  | _        d S ro   )r   rL   r   r~   rY  )rp   r   s     rq   rr   zMethodAdder.__init__  s     &sw|44rs   Nre  r}   r8  list[Argument]rk   rE   rY  rj   rZ  TypeVarType | Nonec           	     n    ||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)rY  r6   r   r   r   )rp   re  r8  rk   rY  rZ  s         rq   r\  zMethodAdder.add_method  sH     "+!6IIDN	HL$(,T8YPS	
 	
 	
 	
 	
rs   r   r   rl   rm   rt   )re  r}   r8  r  rk   rE   rY  rj   rZ  r  rl   rm   )ru   rv   rw   rx   rr   r\  ry   rs   rq   r   r     sS         5 5 5 5 "&"&
 
 
 
 
 
 
rs   r  r?   CallableType | Nonec                8   | j                             t                    }||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   rc   r{  
get_methodrf   r   r   r=   )r  
magic_attrinit_methods      rq   _get_attrs_init_typer    s     o..J!<t(%%j11YSX5H5H5Y5YKk7++ :k>NP\3]3] trs   mypy.plugin.FunctionSigContexttrE   parent_tc                H   t          || j        j                  }||u r"t          |t                    rd| dnd| d}nAt          || j        j                  }t          |t                    r	d| 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   rH   r   r   )r   r  r  t_namer   pt_names         rq   _fail_not_attrs_classr    s    a11F1}} ![))e`6````d&ddd 	 #8SW_== ![))yooovoooox'xxY_xxx 	 GLLck"""""rs   rC   display_typ
parent_typlist[Mapping[str, Type]] | Nonec                   t          |t                    rdS t          |t                    rHg }|                                D ]/}t	          |          }t          | |||          }||||z  }-d}0|S t          |t                    r$t          | t	          |j                  ||          S t          |t                    rt          |          }|t          | ||           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<   rJ   relevant_itemsrK   _get_expanded_attr_typesrH   rS  r?   r  r  r   r
   r   r}   	arg_namesr@  dictr   )
r   r  r  r  retrF  
item_types	init_funcfield_namesfield_typess
             rq   r  r    su    #w t	C	#	# /1&&(( 	 	D"4((D1#tT:NNJ:#9z!
	C	%	% '11;

 
 	
 
C	"	" (--	!#{J???4+Is;;	49i&9!""&=>>)!""-Sk223344c;
;;;trs   r>  list[Mapping[str, Type]]Mapping[str, Type]c                     t          t                    } D ]7}|                                D ] \  }}||                             |           !8 f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           	         i | ]V\  }}|t          |          t                    k    r"t          t          t          |                    nt	                      WS ry   )r   rK   r   r   rI   )r   r|   f_typesr>  s      rq   r   z _meet_fields.<locals>.<dictcomp>  si        D' 	w<<3u::%% fZ99:::  rs   )r   r   rA  r   )r>  field_to_typesfieldsr|   r  s   `    rq   _meet_fieldsr  
  s     !&&N - - 	- 	-ID#4 '',,,,	-    ,1133	   rs   r=   c           
        t          | j                  dk    r5| 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          | |||          }|| j        S t          |          }t          dg|                                t          gt           gt          |          z  z   |g|                                || j        j        | j        j         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  rB  r@  rk   r}  r|   )r   r8  r   r   default_signaturer|   r   rK   get_expression_typer   r   r  r  r=   keysr   r   r   r}  )r   inst_arg	inst_typeinst_type_str
attr_typesr  s         rq   evolve_function_sig_callbackr    sS   
 38}}U.3UUUWZWbccc$$
38A;1$$x{1~H ; ;H E EFFI$Y@@M)#y)YOOJ$$*%%F*FKKMM*)}oF;;/v}}/&/%*????   rs   c                   t          | j                  dk    st          | j        d                   dk    r| j        S t          | j                            | j        d         d                             }t          |t                    s/t          |t                    r!t          |j	        t                    r| j        S d}| j        j
        }t          |t                    r4t          |j                  }t          |t                    r
|g}|j        }n)t          |t                    r|                                }|Et"          |j        v r7|j        t"                   j        }|J | j                            ||          S | j        S )z)Provide the signature for `attrs.fields`.r   r   N)r@  rk   )r   r8  r  rK   r   r  r   r<   rG   rF  r@  rH   rS  r?   r   r=   type_objectrc   r   r  )r   r   r   r@  innerrk   s         rq   fields_function_sig_callbackr  ;  sm   
38}}S!--22$$!#'"="=chqk!n"M"MNNK 	;((%k8,,% {'11%
 $$
C%/I+{++ ( 788eX&& 	$I*C	K	.	. (%%''
?ci779_-2###$22YQY2ZZZ  rs   )r   r   rl   r   ro   )r   r   r|   r}   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   r{   )r   r   r   r   r   r   r  r%   r  r   r  r   rl   r$  )r   r   r1  r2  rl   r   )rH  r&   rl   r   )r  r   r  r   rl   rN  )r   r   r   r   rl   rm   )r   r   r   r   rl   rm   )
r   r   r   r   r   r   re  rf  rl   rm   )r   r   r   rs  rl   rm   )r  r?   rl   r  )r   r  r  rE   r  rE   rl   rm   )
r   r  r  rC   r  rC   r  rC   rl   r  )r>  r  rl   r  )r   r  rl   r=   )rx   
__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/   r0   r1   mypy.plugins.commonr2   r3   r4   r5   r6   r7   mypy.server.triggerr8   mypy.typeopsr9   r:   r;   
mypy.typesr<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   mypy.typevarsrL   	mypy.utilrM   rQ   __annotations__rR   rS   rX   r^   r_   ra   rc   rd   rf   rh   r{   r   r   r   r   r   r   r   r   r   r   r  r  r+  r9  r  r   r   r   r   r   r   r   r  r  r  r  r  r  ry   rs   rq   <module>r     ss   D D D " " " " " " # # # # # #       7 7 7 7 7 7 7 7 7 7 7 7 7 7 % % % % % %     2 2 2 2 2 2 ' ' ' ' ' ' @ @ @ @ @ @ @ @ I I I I I I I I             * * * * * *                                                             > 8 7 7 7 7 7                6 5 5 5 5 5 V V V V V V V V V V                                   $ ( ' ' ' ' '       GFF  F F F F 01  1 1 1 1*N;  ; ; ; ;\\\  \ \ \ \```  ` ` ` `#=?Z"[  [ [ [ [    * * * * *&>  > > > >) ) ) ) )! ! ! ! ! ! ! !y" y" y" y" y" y" y" y"x   < IM    8, , , , ). 	E E E E EP   L L L L^A A A A
   : S  S  S  SF$ $ $ $<X X X X @ @ @ @Fa a a aH      "J J J J<# # # #,(4 (4 (4 (4V$ $ $ $NW W W W"` ` ` `"
 
 
 
 
 
 
 
>
 
 
 
# # # #&' ' ' 'T   "   @!! !! !! !! !! !!rs   