
    7g2                    x   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ ddlmZmZ ddlmZ ddlmZmZmZm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   ed      Z! G d dejD                        Z# G d dejH                        Z% G d dejL                        Z' G d dejL                        Z( G d dejR                        Z* G d dejR                        Z+ G d dejR                        Z, G d dejZ                        Z.ejH                  e(fej^                  _0         G d dejZ                        Z1y )!a"  
Inference objects are a way to represent composite AST nodes,
which are used only as inference results, so they can't be found in the
original AST tree. For instance, inferring the following frozenset use,
leads to an inferred FrozenSet:

    Call(func=Name('frozenset'), args=Tuple(...))
    )annotations)	GeneratorIterator)cached_property)AnyLiteralNoReturnTypeVar)basesutil)InferenceContext)AttributeInferenceErrorInferenceErrorMroError
SuperError)objectmodel)AstroidManager)node_classesscoped_nodes)InferenceResultSuccessfulInferenceResult_Tc                  2    e Zd ZdZddZdddZed        Zy)		FrozenSetz.Class representing a FrozenSet composite node.c                     y)Nzbuiltins.frozenset selfs    /lib/python3.12/site-packages/astroid/objects.pypytypezFrozenSet.pytype'   s    #    Nc              +     K   |  y wNr   r   contextkwargss      r   _inferzFrozenSet._infer*        
   c                R    t               j                  }|j                  d      d   S )N	frozensetr   r   builtins_modulegetattrr   ast_builtinss     r   _proxiedzFrozenSet._proxied-   s&    %'77##K033r!   )returnzLiteral['builtins.frozenset']r#   r%   InferenceContext | Noner&   r   )__name__
__module____qualname____doc__r    r'   r   r1   r   r!   r   r   r   $   s#    8$ 4 4r!   r   c                       e Zd ZdZ ej
                         Z	 	 	 	 	 	 	 	 	 	 	 	 d fdZdddZd Z	e
d        ZddZddZed        Zdd	Z	 d	 	 	 	 	 dd
ZdddZ xZS )Supera  Proxy class over a super call.

    This class offers almost the same behaviour as Python's super,
    which is MRO lookups for retrieving attributes from the parents.

    The *mro_pointer* is the place in the MRO from where we should
    start looking, not counting it. *mro_type* is the object which
    provides the MRO, it can be both a type or an instance.
    *self_class* is the class where the super call is, while
    *scope* is the function where the super call is.
    c                    || _         || _        d| _        || _        || _        t
        |   ||j                  |j                  |j                  |j                         y )NF)parentlineno
col_offset
end_linenoend_col_offset)typemro_pointer_class_based_self_class_scopesuper__init__r=   r>   r?   r@   )r   rB   mro_type
self_classscopecall	__class__s         r   rG   zSuper.__init__B   sb     	&!%<<'''' // 	 	
r!   c              +     K   |  y wr#   r   r$   s      r   r'   zSuper._inferW   r(   r)   c                >   t        | j                  t        j                        st	        d|       t        | j
                  t        j                        rd| _        | j
                  }nNt        | j
                  dd      }t        |t        j                  t        j                  f      st	        d|       |j                  st	        d|       |j                         }| j                  |vrt	        d|       |j                  | j                        }||dz   d S )	zBGet the MRO which will be used to lookup attributes in this super.zIThe first argument to super must be a subtype of type, not {mro_pointer}.)super_Tr1   NzPThe second argument to super must be an instance or subtype of type, not {type}.z*Unable to call super on old-style classes.   )
isinstancerB   r   ClassDefr   rA   rC   r.   r   Instancenewstylemroindex)r   rH   rU   rV   s       r   	super_mrozSuper.super_mroZ   s   $**L,A,AB+  dii!6!67 $DyyHtyy*d;Hh9N9N(OP ?    IRVWWlln3&;  		$**+519;r!   c                R    t               j                  }|j                  d      d   S )NrF   r   r,   r/   s     r   r1   zSuper._proxied~   s&    %'77##G,Q//r!   c                     y)Nzbuiltins.superr   r   s    r   r    zSuper.pytype   s    r!   c                     y)NzSuper ofr   r   s    r   display_typezSuper.display_type   s    r!   c                .    | j                   j                  S )z Get the name of the MRO pointer.)rB   namer   s    r   r]   z
Super.name   s     $$$r!   c                     y)NrF   r   r   s    r   qnamezSuper.qname   s    r!   c           	   #    K   |dk(  r| j                   j                  |       y	 | j                         }d}|D ]N  }||j                  vrd}t        j                  ||   g|| 	      D ]  }t        |t        j                        s| #|j                  d
k(  rt        j                   ||       K| j"                  j                  d
k(  r|j                  dk(  r| x| j$                  s|j                  dk(  r| t        |t&              r)|j(                  }	 |j+                  | |      E d{    t        j2                  |      r	 |j+                  | |      E d{    t        j                   ||        Q |s,|| j                   v r| j                   j                  |       y|st	        | ||      y# t        $ r }t	        d| |||j
                        |d}~wt        $ r+}t	        d| |||j                  |j                        |d}~ww xY w7 # t,        $ r t.        j0                   Y w xY w7 # t,        $ r t.        j0                   Y w xY ww)z9Retrieve the inferred values of the given attribute name.rL   NzHLookup for {name} on {target!r} because super call {super!r} is invalid.)target	attributer%   rO   zJLookup for {name} on {target!r} failed because {cls!r} has an invalid MRO.)ra   rb   r%   mrosclsFT)frameclassmethodmethodstaticmethodcallerr%   )ra   rb   r%   )special_attributeslookuprW   r   r   rO   r   rc   rd   localsr   _infer_stmtsrQ   r   FunctionDefrA   BoundMethodrE   rC   Propertyfunctioninfer_call_resultr   r   Uninferable_is_property)	r   r]   r%   rU   excfoundrd   inferredrr   s	            r   igetattrzSuper.igetattr   sq     ;))0066	.."C4 C3::%E!..D	{G4PP!(L,D,DE"N ==M1++Hc::[[%%68==H;T"N&&(-->*I"N(3'00H/#+#=#=#' $> $  
 ''1/#+#=#=dG#LLL  ++Hc::9 Q J !8!88))0066)wWW C  
	)" zz	 	  	)# XXGG
 
	D * /".../
 M) /".../s   $I2G C)I2!H,7H*8H,<I2I(I)I-AI2	H'G00H'<&H""H''I2*H,,II2
II2II/+I2.I//I2c                :    t        | j                  ||            S )N)r%   )listry   )r   r]   r%   s      r   r.   zSuper.getattr   s    DMM$M899r!   )rB   r   rH   r   rI   zscoped_nodes.ClassDefrJ   zscoped_nodes.FunctionDefrK   znode_classes.Callr2   Noner#   r3   )r2   zLiteral['builtins.super']r2   str)r2   zLiteral['super'])r]   r~   r%   r4   r2   Iterator[InferenceResult])r%   r4   )r5   r6   r7   r8   r   
SuperModelrk   rG   r'   rW   r   r1   r    r[   propertyr]   r_   ry   r.   __classcell__rL   s   @r   r:   r:   3   s    
 0//1
.
 ,
 *	

 (
  
 

*" H 0 0  % % =APXPX"9PX	"PXd: :r!   r:   c                       e Zd ZdZed        Zy)ExceptionInstancezClass for instances of exceptions.

    It has special treatment for some of the exceptions's attributes,
    which are transformed at runtime into certain concrete objects, such as
    the case of .args.
    c                    | j                         }t        j                  j                  |t        j                        }  |       |       S r#   )r_   r   BUILTIN_EXCEPTIONSgetExceptionInstanceModel)r   r_   instances      r   rk   z$ExceptionInstance.special_attributes   s?    

1155;55
 xz$r!   N)r5   r6   r7   r8   r   rk   r   r!   r   r   r      s        r!   r   c                  2    e Zd ZdZ ej
                         Zy)DictInstancezSpecial kind of instances for dictionaries.

    This instance knows the underlying object model of the dictionaries, which means
    that methods such as .values or .items can be properly inferred.
    N)r5   r6   r7   r8   r   	DictModelrk   r   r!   r   r   r      s     /..0r!   r   c                  d    e Zd Zej                  j
                  Zej                  j                  Zy)	DictItemsNr5   r6   r7   r   NodeNG__str____repr__r   r!   r   r   r     $    !!))G""++Hr!   r   c                  d    e Zd Zej                  j
                  Zej                  j                  Zy)DictKeysNr   r   r!   r   r   r   
  r   r!   r   c                  d    e Zd Zej                  j
                  Zej                  j                  Zy)
DictValuesNr   r   r!   r   r   r     r   r!   r   c                  F     e Zd ZdZd fd	Z	 d	 	 	 	 	 d fdZddZ xZS )	PartialFunctionzEA class representing partial function obtained via functools.partial.c                   t         |   |||t        j                         dd       || _        |j
                  dd  | _        |j                  | _        |j
                  d   }t        |j                               }t        |t              r=|j                  | j                  z   | _        i |j                  | j                  | _        t        | j                        | _        y )Nr   r=   r>   r<   r@   r?   rP   )rF   rG   r   Unknownr<   positional_argumentsfilled_argskeyword_argumentsfilled_keywordsnextinferrQ   r   lenfilled_positionals)	r   rK   r]   r=   r>   r<   wrapped_functioninferred_wrapped_functionrL   s	           r   rG   zPartialFunction.__init__  s    !'') 	 	
 44QR8#5544Q7$()9)?)?)A$B!/A8DDtGWGWWD$+;;$&&$D 
 #&d&6&6"7r!   c                   |r|j                   sJ d       |j                   j                  D ch c]  \  }}|	 }}}| j                  j                         D ]1  \  }}||vs|j                   j                  j	                  ||f       3 |j                   j
                  xs g }| j                  |z   |j                   _        t        | !  ||      S c c}}w )Nz6CallContext should be set before inferring call resultri   )	callcontextkeywordsr   itemsappendargsr   rF   rs   )	r   rj   r%   keyword_current_passed_keywordsvaluecall_context_argsrL   s	           r   rs   z!PartialFunction.infer_call_result2  s    
 ##HGH# -4,?,?,H,H',HLWa,H $ ' #'"6"6"<"<">"99''0077%8HI #? !( 3 3 8 8 >B'+'7'7:K'KG$w((HH's   Cc                .    | j                   j                  S r#   )rL   r5   r   s    r   r_   zPartialFunction.qnameG  s    ~~&&&r!   NNNNr#   )rj    SuccessfulInferenceResult | Noner%   r4   r2   r   r}   )r5   r6   r7   r8   rG   rs   r_   r   r   s   @r   r   r     s:    O8< ,0I0I )I 
#	I*'r!   r   c                       e Zd ZdZd fd	Z ej                         ZdZddZ		 d		 	 	 	 	 d
dZ
	 d		 	 	 	 	 	 	 ddZ xZS )rq   z%Class representing a Python property.c                f    || _         t        | 	  |||||j                  |j                         y )Nr   )rr   rF   rG   r@   r?   )r   rr   r]   r=   r>   r<   rL   s         r   rG   zProperty.__init__S  s:     !#22** 	 	
r!   r   c                     y)Nzbuiltins.propertyr   r   s    r   r    zProperty.pytypea  s    "r!   c                    t        d      )NzProperties are not callable)r   )r   rj   r%   s      r   rs   zProperty.infer_call_resultd  s    
 :;;r!   c              +     K   |  y wr#   r   r$   s      r   r'   zProperty._inferk  s      
r)   r   )r2   zLiteral['builtins.property']r#   )rj   r   r%   r4   r2   r	   )r   r   r%   r4   r&   r   r2   zGenerator[_T])r5   r6   r7   r8   rG   r   PropertyModelrk   rA   r    rs   r'   r   r   s   @r   rq   rq   P  sx    /	
 3224D# ,0<0< )< 
	< 6:2EH	r!   rq   N)2r8   
__future__r   collections.abcr   r   	functoolsr   typingr   r   r	   r
   astroidr   r   astroid.contextr   astroid.exceptionsr   r   r   r   astroid.interpreterr   astroid.managerr   astroid.nodesr   r   astroid.typingr   r   r   BaseContainerr   r   r:   rS   r   r   Proxyr   r   r   ro   r   Dict	__bases__rq   r   r!   r   <module>r      s   
 # / % 2 2  ,  , * 4 ET]4** 4q:L q:h   "15>> 1, ,
,u{{ ,
, ,
4'l.. 4'r  ,22LA   |'' r!   