
    yIf.                    .   d Z ddlmZ ddlZddlmZ ddlmZ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 dd
lmZ 	 d2d3dZd4dZd5dZ	 d2d6dZ	 d2d7dZ 	 d2d8d#Z!	 d2d9d$Z"	 d2d:d&Z#d2d;d(Z$d<d)Z%d<d*Z&d<d+Z'd=d.Z(d2d>d/Z)d?d1Z*dS )@zVarious helper utilities.    )annotationsN)	Generator)basesmanagernodesobjectsraw_buildingutil)CallContextInferenceContext)AstroidTypeErrorAttributeInferenceErrorInferenceErrorMroError_NonDeducibleTypeHierarchy)scoped_nodes)InferenceResult)
safe_infernode1nodes.NodeNG | bases.Proxy | util.UninferableBasecontextInferenceContext | NonereturnInferenceResult | Nonec                \    t          j        dt          d           t          | |          S )NzRImport safe_infer from astroid.util; this shim in astroid.helpers will be removed.   )
stacklevelr   )warningswarnDeprecationWarningreal_safe_inferr   r   s     C/var/www/piapp/venv/lib/python3.11/site-packages/astroid/helpers.pyr   r      s;    
 M\   
 41111    cls_namestrbuiltinsnodes.Modulenodes.ClassDefc                <    t          j        |           }||_        |S N)r	   build_classparent)r&   r(   proxys      r$   _build_proxy_classr0   '   s    $X..EELLr%   function6nodes.Lambda | nodes.FunctionDef | bases.UnboundMethodc                    t          | t          j        t          j        f          r#|                                 j        dk    rd}n"d}nt          | t          j                  rd}nd}t          ||          S )Nr(   builtin_function_or_methodr1   method)	
isinstancer   LambdaFunctionDefrootnamer   BoundMethodr0   )r1   r(   r&   s      r$   _function_typer<   -   sv     (\0,2JKLL ==??:--3HH!HH	He/	0	0 h111r%   r   -Generator[InferenceResult | None, None, None]c              #  d  K   t          j                    }|j        }|pt                      }|                     |          D ]k}t          |t          j                  rB|j        r|	                    |          }|r|V  A|
                    d          d         V  _t          |t          j        t          j        t          j        f          rt          ||          V  t          |t          j                  rt#          d|          V  t          |t$          j                  rt(          t          |t*          j                  r|V  t          |t          j        t$          j        t2          j        f          r|j        V  Mt9          dt;          |           d          d S )Nr   typer   modulezWe don't handle z
 currently)r   AstroidManagerbuiltins_moduler   inferr6   r   ClassDefnewstyle	metaclassgetattrr7   r   UnboundMethodr8   r<   Moduler0   r   Unknownr   r
   UninferableBaseProxySlicer   Super_proxiedAssertionErrorr?   )r   r   astroid_managerr(   inferredrF   s         r$   _object_typerS   =   s      ,..O.H+)++GJJwJ// P Ph 566 	P  $..w.??	 #OOO""6**1----- %"5|7OP
 
 	P !8444444,"566 		P$Xx888888%-00 	P  $"677 	PNNNN5;W]"KLL 	P##### !NDNN!N!N!NOOO-P Pr%   c                    	 t          t          | |                    }n# t          $ r t          j        cY S w xY wt          |          dk    s|st          j        S t          t          |                    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.
       )setrS   r   r
   Uninferablelennextiter)r   r   typess      r$   object_typer\   ]   sz     Lw//00       
5zzA~~U~Us     99obj_typeclass_or_seqlist[InferenceResult]util.UninferableBase | boolc                <   t          | t          j                  st          | t          j                  st          j        S d |D             }|D ]L}t          |t          j                  rt          d          |                                 D ]}||k    r  dS MdS )Nc                ^    g | ]*}t          |t          j                  s|nt          j        +S  )r6   r   Instancer
   rW   ).0items     r$   
<listcomp>z,_object_type_is_subclass.<locals>.<listcomp>}   s@        tU^44J$:J  r%   z&arg 2 must be a type or tuple of typesTF)r6   r
   rK   r   rD   rW   r   mro)r]   r^   r   	class_seqklassobj_subclasss         r$   _object_type_is_subclassrl   r   s    
 (D011  %.: :       I   eT122 	M"#KLLL$LLNN 	 	Lu$$ttt %	 5r%   c                    t          | |          }t          |t          j                  rt          j        S t          |||          S )zCheck if a node 'isinstance' any node in class_or_seq.

    :raises AstroidTypeError: if the given ``classes_or_seq`` are not types
    r   )r\   r6   r
   rK   rW   rl   )r   r^   r   r]   s       r$   object_isinstancern      sF     4))H(D011  #HlGLLLLr%   nodes.NodeNGc                ~    t          | t          j                  st          |  d          t	          | ||          S )zCheck if a type is a subclass of any node in class_or_seq.

    :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 noder   )r6   r   rD   	TypeErrorrl   )r   r^   r   s      r$   object_issubclassrr      sD     dEN++ ?4===>>>#D,HHHHr%   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.r   FT)_all_bases_knownAttributeErrorr   r"   r6   r   rD   has_known_bases)rj   r   baseresults       r$   rw   rw      s    %%    	 	 w777 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maprw   r   rE   rh   r   )type1type2es      r$   _type_checkr      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*.r~   r   r   r   s     r$   
is_subtyper      s    U%0000r%   c                "    t          | |          S )z+Check if *type2* is a supertype of *type1*.r   r   s     r$   is_supertyper      s    ue$$$r%   bases.Instance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__r   )argscalleeN)r   igetattrr6   r   r;   	boundnoder   callcontextinfer_call_resultr   Constvalueintr   )r   r   rR   ry   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                L   ddl m} t          | |          }|                                 }t	          |t
          j                  rv|j        dk    rkt	          |t          j	                  rQ|j
        |j        k    rAd                    | j        |                                 j                  }t!          |          |t	          |t"          j                  rt!          |           t	          |t&          j                  r5t	          |j        t,          t.          f          rt1          |j                  S t	          |t&          j        t&          j        t&          j        |f          rt1          |j                  S t	          |t&          j                  rt1          |j                  S t?          ||          }|st!          |           	 tA          |!                    d|                    }nb# tD          $ r"}tG          t/          |                    |d}~wtH          $ r+}tG          d|%                                 d	          |d}~ww xY w|&                    | |          }	t	          |	t"          j                  rt!          | |
          tA          |	d          }
t	          |
t&          j                  r|
%                                dk    r|
j        S |
/t	          |
t          j'                  r|
(                    d          rdS tG          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   )	FrozenSetr   __len__zNSelf referential __len__ function will cause a RecursionError on line {} of {}N)r   zobject of type 'z' has no len()r#   zbuiltins.int'z,' object cannot be interpreted as an integer))astroid.objectsr   r"   framer6   r   r8   r:   r   rL   rO   r.   formatlinenor9   filer   r
   rK   r   r   r   bytesr'   rX   ListSetTupleeltsDictitemsr\   rY   r   StopIterationr   r   pytyper   rd   is_subtype_of)r   r   r   inferred_node
node_framemessage	node_typelen_callr   rR   result_of_lens              r$   
object_lenr      s"    *)))))#D':::M J:|788&Oy((}ek22 )"j&77766<fTYY[[-7 7 	 W%%%
=$:N O O$''''--- (*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(D011 9$88884((M=%+..#  ""n44""mU^44 	''77 	
 q
GMGGG  s$   $G4 4
I>HI(&IInodes.FunctionDef | Nonec                    | }|j         rLt          |j         t          j                  s-|j         }|j         rt          |j         t          j                  -|r|j         r|j         S dS )a  Search for the first function which encloses the given
    scope.

    This can be used for looking up in that function's
    scope, in case looking up in a lower scope for a particular
    name fails.

    :param node: A scope node.
    :returns:
        ``None``, if no parent function scope was found,
        otherwise an instance of :class:`astroid.nodes.scoped_nodes.Function`,
        which encloses the given node.
    N)r.   r6   r   r8   )r   currents     r$   _higher_function_scoper   ?  sp     G
. !GNE<M!N!N !. . !GNE<M!N!N ! 7> ~4r%   r,   )r   r   r   r   r   r   )r&   r'   r(   r)   r   r*   )r1   r2   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   r   r   r`   )r   ro   r^   r_   r   r   r   r`   )r   r   r   rs   )r   rs   )r   r   r   r   )r   r   )r   ro   r   r   )+__doc__
__future__r   r   collections.abcr   astroidr   r   r   r   r	   r
   astroid.contextr   r   astroid.exceptionsr   r   r   r   r   astroid.nodesr   astroid.typingr   astroid.utilr   r"   r0   r<   rS   r\   rl   rn   rr   rw   r   r   r   r   r   r   rc   r%   r$   <module>r      s  
    " " " " " "  % % % % % % F F F F F F F F F F F F F F F F 9 9 9 9 9 9 9 9              ' & & & & & * * * * * * 6 6 6 6 6 6
 (,
2 
2 
2 
2 
2   2 2 2 2" ?CP P P P PB ?C    0 (,    > (,M M M M M$ (,I I I I I     (
0 
0 
0 
01 1 1 1
% % % %
   .M M M M M`     r%   