
    7g2                    `   d 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
mZ erddlmZmZmZmZ ddlmZ dZ G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z  G d! d"e       Z! G d# d$e      Z" G d% d&e      Z# G d' d(e      Z$ G d) d*e      Z% G d+ d,e      Z& G d- d.e      Z' G d/ d0e      Z( G d1 d2e      Z) G d3 d4e)      Z*eZ+e!Z,e"Z-y5)6z<This module contains exceptions used in the astroid library.    )annotations)IterableIterator)TYPE_CHECKINGAny)InferenceResultSuccessfulInferenceResult)	argumentsbasesnodesobjects)InferenceContext)AstroidBuildingErrorAstroidErrorAstroidImportErrorAstroidIndexErrorAstroidSyntaxErrorAstroidTypeErrorAstroidValueErrorAttributeInferenceErrorDuplicateBasesErrorInconsistentMroErrorInferenceErrorInferenceOverwriteErrorMroErrorNameInferenceError	NoDefaultNotFoundErrorParentMissingErrorResolveErrorStatementMissingSuperArgumentTypeError
SuperErrorTooManyLevelsErrorUnresolvableNameUseInferenceDefaultc                  .     e Zd ZdZdd fdZddZ xZS )r   an  Base exception class for all astroid related exceptions.

    AstroidError and its subclasses are structured, intended to hold
    objects representing state when the exception is thrown.  Field
    values are passed to the constructor as keyword-only arguments.
    Each subclass has its own set of standard fields, but use your
    best judgment to decide whether a specific exception instance
    needs more or fewer fields for debugging.  Field values may be
    used to lazily generate the error message: self.message.format()
    will be called with the field names and values supplied as keyword
    arguments.
    c                |    t         |   |       || _        |j                         D ]  \  }}t	        | ||        y N)super__init__messageitemssetattr)selfr,   kwskeyvalue	__class__s        2lib/python3.12/site-packages/astroid/exceptions.pyr+   zAstroidError.__init__<   s7    !))+JCD#u% &    c                L     | j                   j                  di t        |       S N )r,   formatvarsr/   s    r4   __str__zAstroidError.__str__B   s     "t||""0T$Z00r5   ) )r,   strr0   r   returnNoner?   r>   __name__
__module____qualname____doc__r+   r<   __classcell__r3   s   @r4   r   r   .   s    &1r5   r   c                  V     e Zd ZdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   zException class when we are unable to build an astroid representation.

    Standard attributes:
        modname: Name of the module that AST construction failed for.
        error: Exception raised during construction.
    c                z    || _         || _        || _        || _        || _        || _        t        	|   |fi | y r)   )modnameerrorsourcepathcls
class_reprr*   r+   )
r/   r,   rK   rL   rM   rN   rO   rP   r0   r3   s
            r4   r+   zAstroidBuildingError.__init__N   sA     
	$(C(r5   )z"Failed to import module {modname}.NNNNNN)r,   r>   rK   
str | NonerL   zException | NonerM   rQ   rN   rQ   rO   ztype | NonerP   rQ   r0   r   r?   r@   rC   rD   rE   rF   r+   rG   rH   s   @r4   r   r   F   s     <""&!!%)) )  	)
 ) ) ) ) ) 
) )r5   r   c                      e Zd ZdZy)r   z@Exception class used when a module can't be imported by astroid.NrC   rD   rE   rF   r8   r5   r4   r   r   b   s    Jr5   r   c                  >     e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 d fdZ xZS )r$   zException class which is raised when a relative import was beyond the top-level.

    Standard attributes:
        level: The level which was attempted.
        name: the name of the module on which the relative import was attempted.
    c                B    || _         || _        t        |   |fi | y r)   )levelnamer*   r+   )r/   r,   rW   rX   r0   r3   s        r4   r+   zTooManyLevelsError.__init__n   s%     
	(C(r5   )zBRelative import with too many levels ({level}) for module {name!r}NN)
r,   r>   rW   z
int | NonerX   rQ   r0   r   r?   r@   rR   rH   s   @r4   r$   r$   f   sM    ( 
)
) 	
)
 
) 
) 

) 
)r5   r$   c                  >     e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   z3Exception class used when a module can't be parsed.c                ,    t         |   |||||       y r)   )r*   r+   )r/   r,   rK   rL   rN   rM   r3   s         r4   r+   zAstroidSyntaxError.__init__~   s     	'5&$?r5   r)   )r,   r>   rK   rQ   rL   	ExceptionrN   rQ   rM   rQ   r?   r@   rR   rH   s   @r4   r   r   {   sW    = "@@ @ 	@
 @ @ 
@ @r5   r   c                  >     e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 d fdZ xZS )r   zRaised by function's `default_value` method when an argument has
    no default value.

    Standard attributes:
        func: Function node.
        name: Name of argument without a default.
    c                B    || _         || _        t        |   |fi | y r)   )funcrX   r*   r+   )r/   r,   r^   rX   r0   r3   s        r4   r+   zNoDefault.__init__   s%     		(C(r5   )z%{func!r} has no default for {name!r}.NN)
r,   r>   r^   znodes.FunctionDef | NonerX   rQ   r0   r   r?   r@   rR   rH   s   @r4   r   r      sM     ?)-		)	) '	) 		)
 	) 
	) 	)r5   r   c                  6     e Zd ZdZ	 d	 	 	 	 	 	 	 d fdZ xZS )r    zBase class of astroid resolution/inference error.

    ResolveError is not intended to be raised.

    Standard attributes:
        context: InferenceContext object.
    c                4    || _         t        |   |fi | y r)   )contextr*   r+   )r/   r,   ra   r0   r3   s       r4   r+   zResolveError.__init__   s     (C(r5   )r=   N)r,   r>   ra   InferenceContext | Noner0   r   r?   r@   rR   rH   s   @r4   r    r       s9     EI))*A)QT)	) )r5   r    c                  F     e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 d fdZddZ xZS )r   a	  Error raised when there is a problem with method resolution of a class.

    Standard attributes:
        mros: A sequence of sequences containing ClassDef nodes.
        cls: ClassDef node whose MRO resolution failed.
        context: InferenceContext object.
    c                P    || _         || _        || _        t        |   |fi | y r)   )mrosrO   ra   r*   r+   )r/   r,   re   rO   ra   r0   r3   s         r4   r+   zMroError.__init__   s,     	(C(r5   c                    dj                  d | j                  D              }| j                  j                  || j                        S )N, c              3  T   K   | ]   }d dj                  d |D               d " yw)(rg   c              3  4   K   | ]  }|j                     y wr)   )rX   ).0bs     r4   	<genexpr>z-MroError.__str__.<locals>.<genexpr>.<genexpr>   s     +>AqAFFAs   )N)join)rk   ms     r4   rm   z#MroError.__str__.<locals>.<genexpr>   s*     U9a$))+>A+>">!?qA9s   &()re   rO   )ro   re   r,   r9   rO   )r/   	mro_namess     r4   r<   zMroError.__str__   s8    IIU499UU	||""	txx"@@r5   r)   )r,   r>   re   z"Iterable[Iterable[nodes.ClassDef]]rO   znodes.ClassDefra   rb   r0   r   r?   r@   rA   rB   rH   s   @r4   r   r      sR     ,0)) 1) 	)
 )) ) 
)Ar5   r   c                      e Zd ZdZy)r   zDError raised when there are duplicate bases in the same class bases.NrT   r8   r5   r4   r   r      s    Nr5   r   c                      e Zd ZdZy)r   z0Error raised when a class's MRO is inconsistent.NrT   r8   r5   r4   r   r      s    :r5   r   c                  ,     e Zd ZdZd fdZddZ xZS )r#   zError raised when there is a problem with a *super* call.

    Standard attributes:
        *super_*: The Super instance that raised the exception.
        context: InferenceContext object.
    c                4    || _         t        |   |fi | y r)   )super_r*   r+   )r/   r,   rv   r0   r3   s       r4   r+   zSuperError.__init__   s    (C(r5   c                `     | j                   j                  di t        | j                        S r7   )r,   r9   r:   rv   r;   s    r4   r<   zSuperError.__str__   s%    "t||""7T$++%677r5   )r,   r>   rv   zobjects.Superr0   r   r?   r@   rA   rB   rH   s   @r4   r#   r#      s    )8r5   r#   c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   zRaised when we are unable to infer a node.

    Standard attributes:
        node: The node inference was called on.
        context: InferenceContext object.
    c                   || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        || _        || _        || _        || _        || _        t#        | H  |fi | y r)   )nodera   targettargets	attributeunknownassign_pathcallerstmtsframe	call_siter^   argpositional_argumentsunpacked_argskeyword_argumentsunpacked_kwargsr*   r+   )r/   r,   rz   ra   r{   r|   r}   r~   r   r   r   r   r   r^   r   r   r   r   r   r0   r3   s                       r4   r+   zInferenceError.__init__   s    , 	"&

"	$8!*!2.(C(r5   )zInference failed for {node!r}.NNNNNNNNNNNNNNNNN)(r,   r>   rz   InferenceResult | Nonera   rb   r{   r   r|   r   r}   rQ   r~   r   r   zlist[int] | Noner   z SuccessfulInferenceResult | Noner   z Iterator[InferenceResult] | Noner   r   r   zarguments.CallSite | Noner^   r   r   rQ   r   list | Noner   r   r   dict | Noner   r   r0   r   r?   r@   rR   rH   s   @r4   r   r      s    8'++/)-*. $*.(,3726(,/3'+,0%))-'+'')') %') )	')
 '') (') ') (') &') 1') 0') &') -') %') ')  *!')" ##')$ '%')& %'')( )')* 
+') ')r5   r   c                  D     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   a  Raised when a name lookup fails, corresponds to NameError.

    Standard attributes:
        name: The name for which lookup failed, as a string.
        scope: The node representing the scope in which the lookup occurred.
        context: InferenceContext object.
    c                P    || _         || _        || _        t        |   |fi | y r)   )rX   scopera   r*   r+   )r/   r,   rX   r   ra   r0   r3   s         r4   r+   zNameInferenceError.__init__  ,     	
(C(r5   )z {name!r} not found in {scope!r}.NNN)r,   r>   rX   rQ   r   znodes.LocalsDictNodeNG | Nonera   rb   r0   r   r?   r@   rR   rH   s   @r4   r   r     sZ     :/3+/)) ) -	)
 )) ) 
) )r5   r   c                  V     e Zd ZdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   a  Raised when an attribute lookup fails, corresponds to AttributeError.

    Standard attributes:
        target: The node for which lookup failed.
        attribute: The attribute for which lookup failed, as a string.
        context: InferenceContext object.
    c                z    || _         || _        || _        || _        || _        || _        t        	|   |fi | y r)   )r}   r{   ra   re   rv   rO   r*   r+   )
r/   r,   r}   r{   ra   re   rv   rO   r0   r3   s
            r4   r+   z AttributeInferenceError.__init__5  sA     #	(C(r5   )z&{attribute!r} not found on {target!r}.r=   NNNNN)r,   r>   r}   r>   r{   z(nodes.NodeNG | bases.BaseInstance | Nonera   rb   re   zlist[nodes.ClassDef] | Nonerv   nodes.ClassDef | NonerO   r   r0   r   r?   r@   rR   rH   s   @r4   r   r   ,  s     @;?+/,0(,%))) ) 9	)
 )) *) &) #) ) 
) )r5   r   c                      e Zd ZdZy)r&   zyException to be raised in custom inference function to indicate that it
    should go back to the default behaviour.
    NrT   r8   r5   r4   r&   r&   I      r5   r&   c                      e Zd ZdZy)_NonDeducibleTypeHierarchyz[Raised when is_subtype / is_supertype can't deduce the relation between two
    types.
    NrT   r8   r5   r4   r   r   O  r   r5   r   c                  D     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   z@Raised when an Indexable / Mapping does not have an index / key.c                P    || _         || _        || _        t        |   |fi | y r)   rz   indexra   r*   r+   r/   r,   rz   r   ra   r0   r3   s         r4   r+   zAstroidIndexError.__init__X  r   r5   r=   NNNr,   r>   rz   z$nodes.NodeNG | bases.Instance | Noner   znodes.Subscript | Nonera   rb   r0   r   r?   r@   rR   rH   s   @r4   r   r   U  sX    J 59(,+/)) 3) &	)
 )) ) 
) )r5   r   c                  D     e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )r   z9Raised when a TypeError would be expected in Python code.c                P    || _         || _        || _        t        |   |fi | y r)   r   r   s         r4   r+   zAstroidTypeError.__init__i  r   r5   r   r   rR   rH   s   @r4   r   r   f  sX    C 59(,+/)) 3) &	)
 )) ) 
) )r5   r   c                      e Zd ZdZy)r   z:Raised when a ValueError would be expected in Python code.NrT   r8   r5   r4   r   r   w  s    Dr5   r   c                      e Zd ZdZy)r   zYRaised when an inference tip is overwritten.

    Currently only used for debugging.
    NrT   r8   r5   r4   r   r   {  s    r5   r   c                  $     e Zd ZdZd fdZ xZS )r   zRaised when a node which is expected to have a parent attribute is missing one.

    Standard attributes:
        target: The node for which the parent lookup failed.
    c                <    || _         t        | 	  d|d       y )NzParent not found on .r,   )r{   r*   r+   r/   r{   r3   s     r4   r+   zParentMissingError.__init__  s$    #7z!CDr5   r{   znodes.NodeNGr?   r@   rR   rH   s   @r4   r   r     s    E Er5   r   c                  $     e Zd ZdZd fdZ xZS )r!   a  Raised when a call to node.statement() does not return a node.

    This is because a node in the chain does not have a parent attribute
    and therefore does not return a node for statement().

    Standard attributes:
        target: The node for which the parent lookup failed.
    c                4    t         t        |   d|       y )NzStatement not found on r   )r*   r   r+   r   s     r4   r+   zStatementMissing.__init__  s"     $0-fZ8 	1 	
r5   r   rR   rH   s   @r4   r!   r!     s    
 
r5   r!   N).rF   
__future__r   collections.abcr   r   typingr   r   astroid.typingr   r	   astroidr
   r   r   r   astroid.contextr   __all__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   r8   r5   r4   <module>r      sV  
 C " . % E880819 10)< )8K- K)+ )*@- @) )*)< ) A| A6O( O;8 ;8 8 /)\ /)h) ).)l ):)  ) )")| )"E El 	E 	E
) 
  $ % 'r5   