
    c+                       d 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m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 d)dZd*dZ	 d+d,dZ	 d+d-dZ	 d+d.dZd+d.dZd+d.dZ	 d+d/d Z d+d0d"Z!d1d#Z"d1d$Z#d1d%Z$d2d'Z%d+d.d(Z&dS )3zVarious helper utilities.    )annotations)	Generator)basesmanagernodesraw_buildingutil)CallContextInferenceContext)AstroidTypeErrorAttributeInferenceErrorInferenceErrorMroError_NonDeducibleTypeHierarchy)scoped_nodes)InferenceResultSuccessfulInferenceResultcls_namestrbuiltinsnodes.Modulereturnnodes.ClassDefc                <    t          j        |           }||_        |S N)r   build_classparent)r   r   proxys      /lib/python3.11/site-packages/astroid/helpers.py_build_proxy_classr       s    $X..EELL    function"nodes.Lambda | bases.UnboundMethodc                    t          | t          j                  r#|                                 j        dk    rd}n"d}nt          | t
          j                  rd}nd}t          ||          S )Nr   builtin_function_or_methodr"   method)
isinstancer   Lambdarootnamer   BoundMethodr    )r"   r   r   s      r   _function_typer,      sp     (L/00 ==??:- 	"3HH!HH	He/	0	0 h111r!   Nnoder   contextInferenceContext | None-Generator[InferenceResult | None, None, None]c              #    K   t          j                    }|j        }|pt                      }|                     |          D ]H}t          |t          j                  rB|j        r|	                    |          }|r|V  A|
                    d          d         V  _t          |t          j        t          j        f          rt          ||          V  t          |t          j                  rt!          d|          V  t          |t"          j                  rt&          |t(          j        u r|V  t          |t          j        t"          j        f          r|j        V  *t3          dt5          |           d          d S )Nr.   typer   modulezWe don't handle z
 currently)r   AstroidManagerbuiltins_moduler   inferr'   r   ClassDefnewstyle	metaclassgetattrr(   r   UnboundMethodr,   Moduler    r   Unknownr   r	   UninferableProxySlice_proxiedAssertionErrorr3   )r-   r.   astroid_managerr   inferredr:   s         r   _object_typerF   -   s      ,..O.H+)++GJJwJ// P Ph 566 	P  $..w.??	 #OOO""6**1-----<#68K"LMM 	P 8444444,"566 		P$Xx888888%-00 	P  )) 	PNNNN5;"<== 	P##### !NDNN!N!N!NOOO'P Pr!   InferenceResult | Nonec                    	 t          t          | |                    }n# t          $ r t          j        cY S w xY wt          |          dk    s|st          j        S t          |          d         S )aV  Obtain the type of the given node.

    This is used to implement the ``type`` builtin, which means that it's
    used for inferring type calls, as well as used in a couple of other places
    in the inference.
    The node will be inferred first, so this function can support all
    sorts of objects, as long as they support inference.
       r   )setrF   r   r	   r?   lenlist)r-   r.   typess      r   object_typerN   J   s|     Lw//00       
5zzA~  U  ;;q>s     99c                   t          |t          t          f          s|f}n|}| t          j        u rt          j        S d |D             }|D ]@}|t          j        u rt          d          |                                 D ]}||k    r  dS AdS )Nc                ^    g | ]*}t          |t          j                  s|nt          j        +S  )r'   r   Instancer	   r?   ).0items     r   
<listcomp>z,_object_type_is_subclass.<locals>.<listcomp>k   s@        tU^44J$:J  r!   z&arg 2 must be a type or tuple of typesTF)r'   tuplerL   r	   r?   r   mro)obj_typeclass_or_seqr.   	class_seqklassobj_subclasss         r   _object_type_is_subclassr]   _   s     lUDM22 !!O		 	4##     I   D$$ 	M"#KLLL$LLNN 	 	Lu$ ttt	 5r!   c                z    t          | |          }|t          j        u rt          j        S t          |||          S )zCheck if a node 'isinstance' any node in class_or_seq.

    :param node: A given node
    :param class_or_seq: Union[nodes.NodeNG, Sequence[nodes.NodeNG]]
    :rtype: bool

    :raises AstroidTypeError: if the given ``classes_or_seq`` are not types
    r2   )rN   r	   r?   r]   )r-   rY   r.   rX   s       r   object_isinstancer_   |   sA     4))H4##  #HlGLLLLr!   c                ~    t          | t          j                  st          |  d          t	          | ||          S )as  Check if a type is a subclass of any node in class_or_seq.

    :param node: A given node
    :param class_or_seq: Union[Nodes.NodeNG, Sequence[nodes.NodeNG]]
    :rtype: bool

    :raises AstroidTypeError: if the given ``classes_or_seq`` are not types
    :raises AstroidError: if the type of the given node cannot be inferred
        or its type's mro doesn't work
    z needs to be a ClassDef noder2   )r'   r   r8   	TypeErrorr]   )r-   rY   r.   s      r   object_issubclassrb      sD     dEN++ ?4===>>>#D,HHHHr!   nodes.NodeNG | bases.Proxyc                    	 |                      |          }t          |          }n# t          t          f$ r Y dS w xY w	 t          |           dS # t          $ r Y dS t          $ r |cY S w xY w)zReturn the inferred value for the given node.

    Return None if inference failed or if there is some ambiguity (more than
    one node has been inferred).
    r2   N)r7   nextr   StopIteration)r-   r.   inferitvalues       r   
safe_inferri      s    **W*--WM*   ttWt   tt   s$   %( ==A 
A-A-,A-boolc                    	 | j         S # t          $ r Y nw xY w| j        D ]L}t          ||          }t	          |t
          j                  r|| u st          ||          s
d| _          dS Md| _         dS )z=Return whether all base classes of a class could be inferred.r2   FT)_all_bases_knownAttributeErrorr   ri   r'   r   r8   has_known_bases)r[   r.   baseresults       r   rn   rn      s    %%    	 	D'222 6<#899		 #67;;;	
 &+E"55	 "E4s   	 
c                   t          t          t          | |f                    st          t          | j        |j        g          sdS 	 | |                                d d         v S # t          $ r}t          |d }~ww xY w)NF)allmaprn   r   r9   rW   r   )type1type2es      r   _type_checkrx      s    s?UEN3344 )((/00 u0		CRC((( 0 0 0(a/0s   
A( (
A?2A::A?c                $    t          ||           S )z)Check if *type1* is a subtype of *type2*.ru   rv   rx   rz   s     r   
is_subtyper|      s    U%0000r!   c                "    t          | |          S )z+Check if *type2* is a supertype of *type1*.r{   rz   s     r   is_supertyper~      s    ue$$$r!   nodes.Const | Nonec                   t                      }	 |                     d|          D ]}t          |t          j                  s| |_        t          g |          |_        |                    | |          D ]<}t          |t          j
                  r t          |j        t                    r|c c S =n# t          $ r Y nw xY wdS )zGet the value as an index for the given instance.

    If an instance provides an __index__ method, then it can
    be used in some scenarios where an integer is expected,
    for instance when multiplying or subscripting a list.
    	__index__r2   )argscalleeN)r   igetattrr'   r   r+   	boundnoder
   callcontextinfer_call_resultr   Constrh   intr   )r-   r.   rE   rp   s       r   class_instance_as_indexr      s       Gk7CC 	" 	"Hh(9::  $G"-2h"G"G"GG"44T74KK " "fek22 "z&,PS7T7T "!MMMMM"	"    4s   B#B7 4B7 7
CCc                   ddl m} t          | |          }|                     d          }t	          |t
          j                  rl|j        dk    rat          |d          rQ|j	        |j
        k    rAd                    | j        |                                 j                  }t          |          ||t           j        u rt          | 
          t	          |t$          j                  r5t	          |j        t*          t,          f          rt/          |j                  S t	          |t$          j        t$          j        t$          j        |f          rt/          |j                  S t	          |t$          j                  rt/          |j                  S t=          ||          }|st          | 
          	 t?          |                     d|                    }nb# tB          $ r"}tE          t-          |                    |d	}~wtF          $ r+}tE          d|$                                 d          |d	}~ww xY w|%                    | |          }	|	t           j        u rt          | |          t?          |	d	          }
t	          |
t$          j                  r|
$                                dk    r|
j        S |
/t	          |
tL          j'                  r|
(                    d          rdS tE          d|
 d          )a  Infer length of given node object.

    :param Union[nodes.ClassDef, nodes.Instance] node:
    :param node: Node to infer length of

    :raises AstroidTypeError: If an invalid node is returned
        from __len__ method or no __len__ method exists
    :raises InferenceError: If the given node cannot be inferred
        or if multiple nodes are inferred or if the code executed in python
        would result in a infinite recursive check for length
    :rtype int: Integer length of node
    r   )	FrozenSetr2   T)future__len__rB   zNSelf referential __len__ function will cause a RecursionError on line {} of {}N)r-   zobject of type 'z' has no len())r-   r.   zbuiltins.int'z,' object cannot be interpreted as an integer))astroid.objectsr   ri   framer'   r   FunctionDefr*   hasattrrB   r   formatlinenor)   filer   r	   r?   r   r   rh   bytesr   rK   ListSetTupleeltsDictitemsrN   re   r   rf   r   r   pytyper   r   rR   is_subtype_of)r-   r.   r   inferred_node
node_framemessage	node_typelen_callrw   rE   result_of_lens              r   
object_lenr      s0    *)))))tW555M 4((J:|788&Oy(& M:..& "j&77	&66<fTYY[[-7 7 	 W%%% (1A A ($''''--- (*eS\3 3 ( =&'''-%*eii!PQQ '=%&&&-,, (=&'''M7;;;I ($''''	**9g*FFGG . . .s1vv&&A-"   Ay//11AAA
 
	
 ))$88H4## 9$88884((M=%+..#  ""n4# ""mU^44 ''77 q
GMGGG  s$   ;$G   
H?*HH?&H::H?)r   r   r   r   r   r   )r"   r#   r   r   r   r   r   )r-   r   r.   r/   r   r0   )r-   r   r.   r/   r   rG   )r.   r/   )r-   rc   r.   r/   r   rG   )r.   r/   r   rj   )r   rj   )r-   r   r   r   )'__doc__
__future__r   collections.abcr   astroidr   r   r   r   r	   astroid.contextr
   r   astroid.exceptionsr   r   r   r   r   astroid.nodesr   astroid.typingr   r   r    r,   rF   rN   r]   r_   rb   ri   rn   rx   r|   r~   r   r   rQ   r!   r   <module>r      sa  
    " " " " " " % % % % % % = = = = = = = = = = = = = = 9 9 9 9 9 9 9 9              ' & & & & & E E E E E E E E   2 2 2 2  IMP P P P P< IM    , @D    :M M M M MI I I I I" JN    ,    (
0 
0 
0 
01 1 1 1
% % % %
   .M M M M M M Mr!   