o
    7f                     @  s   U d Z ddlmZ ddlmZmZ ddlZddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZmZmZmZmZ dhZd	ed
< h dZd	ed< G dd deZ	ddddZd ddZd!ddZdS )"z<Plugin for supporting the functools standard library module.    )annotations)Final
NamedTupleN)ARG_POS	ARG_STAR2ArgumentFuncItemVar)add_method_to_class)AnyTypeCallableTypeType	TypeOfAnyUnboundTypeget_proper_typezfunctools.total_orderingr   functools_total_ordering_makers>   __ge____gt____le____lt___ORDERING_METHODSc                   @  s   e Zd ZU ded< ded< dS )_MethodInfobool	is_staticr   typeN)__name__
__module____qualname____annotations__ r   r   O/home/ertert/spirit/venv/lib/python3.10/site-packages/mypy/plugins/functools.pyr      s   
 r   Fctxmypy.plugin.ClassDefContextauto_attribs_defaultr   returnc           
        s   t |   s| jd| j dS t  fddd} | }|s"dS t|}| jd}|}|jj| jdkrRt	|jj}t
|trM|jdd d	ksRttj}tD ]} |spttd
||dtg}	t| j| j||	| qTdS )zFAdd dunder methods to classes decorated with functools.total_ordering.zNNo ordering operation defined when using "functools.total_ordering": < > <= >=Tc                   s    |  d u | fS )Nr   )kcomparison_methodsr   r    <lambda>#   s    z9functools_total_ordering_maker_callback.<locals>.<lambda>)keyzbuiltins.bool.r   otherN)_analyze_classapifailreasonmax_find_other_type
named_typer   ret_typer   
isinstancer   namesplitr   r   implementation_artifactr   getr   r	   r   r
   cls)
r!   r#   rootroot_method
other_type	bool_typer4   proper_ret_typeadditional_opargsr   r&   r    'functools_total_ordering_maker_callback   s4   

rB   methodr   c                 C  sz   | j rdnd}d}d}t| jj| jjD ]\}}| r)||kr$|} n|d7 }q|tkr1|} nq|du r;ttj	S |S )z?Find the type of the ``other`` argument in a comparison method.r      N)
r   zipr   	arg_kinds	arg_typesis_positionalr   r   r   r8   )rC   first_arg_poscur_pos_arg	other_argarg_kindarg_typer   r   r    r2   =   s    

r2   dict[str, _MethodInfo | None]c                 C  s   i }| j jjdd D ]G}tD ]B}||jv rQ||vrQ|j| j}t|tr5t|jt	r5t
|j|j||< qt|trMt|j}t|t	rMt
|j|||< qd||< qq|S )zMAnalyze the class body, its parents, and return the comparison methods found.Nr+   )r:   infomror   namesnoder5   r   r   r   r   r   r	   r   is_staticmethod)r!   r'   r:   r6   rR   proper_typer   r   r    r-   S   s"   


r-   )F)r!   r"   r#   r   r$   r   )rC   r   r$   r   )r!   r"   r$   rN   )__doc__
__future__r   typingr   r   mypy.pluginmypy
mypy.nodesr   r   r   r   r	   mypy.plugins.commonr
   
mypy.typesr   r   r   r   r   r   r   r   r   r   rB   r2   r-   r   r   r   r    <module>   s     
'