
    c:                       d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZmZmZ ddlZddlmZ ddlmZ dd	lmZ eeegej        f         egeej                 f         Zd,dZd-dZ G d d          Z G d d          Z G d deej                  Z G d de          Z G d de          Z  G d d e           Z! G d! d"e           Z"ed#ej#        fd.d+Z$dS )/z|Visitor doing some post-processing on the astroid tree.

Try to resolve definitions (namespace) dictionary, relationship...
    )annotationsN)ABCabstractmethod)	Generator)AnyCallableOptional)nodes)	constants)utilsfuncCallable[[str], nodes.Module]modnamestrreturnnodes.Module | Nonec                    t          d| d           	  | |          S # t          j        j        $ r}t          |           Y d }~n&d }~wt          $ r t          j                     Y nw xY wd S )Nzparsing z...)printastroid
exceptionsAstroidBuildingException	Exception	traceback	print_exc)r   r   excs      :lib/python3.11/site-packages/pylint/pyreverse/inspector.py_astroid_wrapperr      s     

!W
!
!
!"""tG}}6   c







   4s   
  A+A A+*A+nodenodes.ClassDefGenerator[Any, None, None]c              #    K   	 t           j                            |                               d          d         }n# t           j        j        $ r Y dS w xY w|                    d          | urdS t                      }d}t          j	        |          D ]0}|t           j
        u rd}||vr|                    |           |V  1|rt           j                                        dS )zEReturn an iterator on interfaces implemented by the given class node.__implements__r   NTfutureF)r   basesInstancegetattrr   NotFoundErrorframesetr
   unpack_inferUninferableaddInferenceError)r   
implementsfoundmissingifaces        r   
interfacesr3   *   s     ]++D1199:JKKAN

+   t$$D0 EEEG#J//  G'' 	G 	IIeKKK 2 //1112 2s   8= AAc                  .    e Zd ZdZdddZdddZdd	Zd
S )IdGeneratorMixInz1Mixin adding the ability to generate integer uid.r   start_valueintr   Nonec                    || _         d S Nid_countselfr6   s     r   __init__zIdGeneratorMixIn.__init__B   s    #    c                    || _         dS )zInit the id counter.Nr;   r=   s     r   init_counterzIdGeneratorMixIn.init_counterE   s    #r@   c                0    | xj         dz  c_         | j         S )zGenerate a new identifier.   r;   r>   s    r   generate_idzIdGeneratorMixIn.generate_idI   s    }r@   N)r   )r6   r7   r   r8   )r   r7   )__name__
__module____qualname____doc__r?   rB   rF    r@   r   r5   r5   ?   s`        ;;$ $ $ $ $$ $ $ $ $     r@   r5   c                  <    e Zd ZdZdddZdd
ZddZddZddZdS )Projectz-A project handle a set of modules / packages. namer   c                    || _         d | _        d| _        g | _        i | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j	        | _	        d S )NrN   )
rO   uidpathmoduleslocals__getitem____iter__valueskeysitemsr>   rO   s     r   r?   zProject.__init__R   sf    	#	+-/1;2,k(K$	[&


r@   r   nodes.Moduler   r8   c                X    || j         |j        <   | j                            |           d S r:   )rT   rO   rS   appendr>   r   s     r   
add_modulezProject.add_module^   s,    !%DID!!!!!r@   c                    | j         |         S r:   )rT   rZ   s     r   
get_modulezProject.get_moduleb   s    {4  r@   list[nodes.Module]c                    | j         S r:   )rS   rE   s    r   get_childrenzProject.get_childrene   s
    |r@   c                b    d| j         dt          |            dt          | j                   dS )Nz	<Project z at z (z
 modules)>)rO   idlenrS   rE   s    r   __repr__zProject.__repr__h   s5    U49UUBtHHUUDL8I8IUUUUr@   N)rN   )rO   r   r   r[   r   r8   )rO   r   r   r[   )r   rb   )r   r   )	rG   rH   rI   rJ   r?   r_   ra   rd   rh   rK   r@   r   rM   rM   O   s        77
' 
' 
' 
' 
'" " " "! ! ! !   V V V V V Vr@   rM   c                  |    e Zd ZdZd$d%d	Zd&dZd'dZd(dZd)dZd*dZ	e
d+d            Zd,dZd-dZd.dZd/d"Zd#S )0Linkera  Walk on the project tree and resolve relationships.

    According to options the following attributes may be
    added to visited nodes:

    * uid,
      a unique identifier for the node (on astroid.Project, astroid.Module,
      astroid.Class and astroid.locals_type). Only if the linker
      has been instantiated with tag=True parameter (False by default).

    * Function
      a mapping from locals names to their bounded value, which may be a
      constant like a string or an integer, or an astroid node
      (on astroid.Module, astroid.Class and astroid.Function).

    * instance_attrs_type
      as locals_type but for klass member attributes (only on astroid.Class)

    * associations_type
      as instance_attrs_type but for association relationships

    * aggregations_type
      as instance_attrs_type but for aggregations relationships

    * implements,
      list of implemented interface _objects_ (only on astroid.Class nodes)
    FprojectrM   tagboolr   r8   c                   t                               |            t          j                            |            || _        || _        t                      | _        | j                            t                                 d S r:   )
r5   r?   r   LocalsVisitorrm   rl   AggregationsHandlerassociations_handlerset_nextOtherAssociationsHandler)r>   rl   rm   s      r   r?   zLinker.__init__   sm    !!$'''$$T***$7$9$9!!**+C+E+EFFFFFr@   r   c                    | j         r|                                 |_        |j        D ]}|                     |           dS )zbVisit a pyreverse.utils.Project node.

        * optionally tag the node with a unique id
        N)rm   rF   rQ   rS   visit)r>   r   modules      r   visit_projectzLinker.visit_project   sQ    
 8 	*''))DHl 	 	FJJv	 	r@   r[   c                    t          |d          rdS t          j        t                    |_        g |_        | j        r|                                 |_        dS dS )zVisit an astroid.Module node.

        * set the locals_type mapping
        * set the depends mapping
        * optionally tag the node with a unique id
        locals_typeN)	hasattrcollectionsdefaultdictlistrz   dependsrm   rF   rQ   r^   s     r   visit_modulezLinker.visit_module   s`     4'' 	F&24888 	*''))DHHH	* 	*r@   r   c                   t          |d          rdS t          j        t                    |_        | j        r|                                 |_        |                    d          D ]/}t          |dg           }|
                    |           ||_        0t          j        t                    |_        t          j        t                    |_        t          j        t                    |_        t          |j                                                  D ]R}|D ]M}t%          |t&          j                  s1| j                            ||           |                     ||           NS	 t1          |          }|9t          |          |_        |j        rt5          j        dt8                     dS dS g |_        dS # t:          j        $ r g |_        Y dS w xY w)zVisit an astroid.Class node.

        * set the locals_type and instance_attrs_type mappings
        * set the implements list and build it
        * optionally tag the node with a unique id
        rz   NF)recursspecializationszpyreverse will drop support for resolving and displaying implemented interfaces in pylint 3.0. The implementation relies on the '__implements__'  attribute proposed in PEP 245, which was rejected in 2006.)r{   r|   r}   r~   rz   rm   rF   rQ   	ancestorsr'   r]   r   instance_attrs_typeaggregations_typeassociations_typetupleinstance_attrsrW   
isinstancer
   Unknownrr   handlehandle_assignattr_typer3   r/   warningswarnDeprecationWarningr   r.   )r>   r   baseobjr   assignattrs
assignattrifacess          r   visit_classdefzLinker.visit_classdef   s    4'' 	F&24888 	*''))DH~~U~33 	6 	6G%g/@"EEO""4(((&5G###.#:4#@#@ !,!8!>!>!,!8!>!> !4!;!;!=!=>> 	B 	BK) B B
!*em<< B-44ZFFF//
DAAAB
	!%%F %"&v,,? M8 +      #%% 	! 	! 	! DOOOO	!s   +AF> 5F> >GGnodes.FunctionDefc                    t          |d          rdS t          j        t                    |_        | j        r|                                 |_        dS dS )zVisit an astroid.Function node.

        * set the locals_type mapping
        * optionally tag the node with a unique id
        rz   N)r{   r|   r}   r~   rz   rm   rF   rQ   r^   s     r   visit_functiondefzLinker.visit_functiondef   sY     4'' 	F&24888 	*''))DHHH	* 	*r@   nodes.AssignNamec                r   t          |d          rdS d|_        |j        |                    d          v r|                    d          }n|                                }t          |d          sut          |t          j                  r|                     |           nEt          |t          j	                  r| 
                    |           n|                     |           |j        |j                 }t          t          |          t          j        |          z            |j        |j        <   dS )zFVisit an astroid.AssignName node.

        handle locals_type
        _handledNTr#   rz   )r{   r   rO   r)   rootr   r
   ClassDefr   FunctionDefr   r   rz   r~   r*   r   
infer_node)r>   r   r)   currents       r   visit_assignnamezLinker.visit_assignname   s$    4$$ 	F9

$
/// 	 JJdJ++EE IIKKEum,, 		) %00 )##E****E5#455 )&&u----!!%(((#DI.'+CLL5;KD;Q;Q,Q'R'R$)$$$r@   nodes.AssignAttrparentc                    t          |j        | j                           }t          |t	          j        |           z            |j        | j        <   dS )zOHandle an astroid.assignattr node.

        handle instance_attrs_type
        N)r*   r   attrnamer~   r   r   )r   r   r   s      r   r   zLinker.handle_assignattr_type  sM     f0?@@48e&t,,,5
 5
"4=111r@   nodes.Importc                    |                                 j        }|j        D ]E}t          j                            |d         |          }|                     ||d         |           FdS )zKVisit an astroid.Import node.

        resolve module dependencies
        r   N)r   filenamesr   modutilsis_relative_imported_module)r>   r   context_filerO   relatives        r   visit_importzLinker.visit_import  sj    
 yy{{'J 	; 	;D'33DG\JJH!!$Q::::	; 	;r@   nodes.ImportFromc                   |j         }|                                j        }|!t          j                            ||          }nd}|j        D ]}|d         dk    r| d|d          }|                    d          dk    r2	 t          j                            ||          }n# t          $ r Y cw xY w||k    r| 
                    |||           dS )zOVisit an astroid.ImportFrom node.

        resolve module dependencies
        NFr   *.)r   r   r   r   r   r   r   findget_module_partImportErrorr   )r>   r   basenamer   r   rO   fullnames          r   visit_importfromzLinker.visit_importfrom  s
   
 <yy{{' 	'33HlKKHHHJ 	@ 	@DAw#~ "..T!W..H}}S!!B& &/??,WWHH"   H8# @%%dHh???	@ 	@s    B$$
B10B1context_namer   mod_pathr7   c                    t           j                            | j        j                  }||k    rdS t          j                            ||f          rdS dS )z:Return true if the module should be added to dependencies.r   rD   )osrR   dirnamerl   r   r   is_standard_module)r>   r   r   package_dirs       r   compute_modulezLinker.compute_module/  sS    goodl&7888# 	1..x+HH 	1qr@   nodes.Import | nodes.ImportFromr   c                L   |                                 }|j        }|r5d                    |                    d          dd                    d| }|                     ||          r9t          |d          sg |_        |j        }||vr|                    |           dS dS dS )z8Notify an imported module, used to analyze dependencies.r   Nr   r   )r   rO   joinsplitr   r{   r   r]   )r>   r   r   r   rw   r   	mod_pathss          r   r   zLinker._imported_module8  s     { 	N((<#5#5c#:#:3B3#?@@MM8MMH|X66 	+69-- $!#Iy( +  *****	+ 	+
+ +r@   N)F)rl   rM   rm   rn   r   r8   )r   rM   r   r8   ri   )r   r   r   r8   )r   r   r   r8   )r   r   r   r8   r   r   r   r   r   r8   )r   r   r   r8   )r   r   r   r8   )r   r   r   r   r   r7   )r   r   r   r   r   rn   r   r8   )rG   rH   rI   rJ   r?   rx   r   r   r   r   staticmethodr   r   r   r   r   rK   r@   r   rk   rk   l   s        8G G G G G   * * * *+! +! +! +!Z
* 
* 
* 
*S S S S< 
 
 
 \
; ; ; ;@ @ @ @0   + + + + + +r@   rk   c                  >    e Zd Zedd            Zedd	            Zd
S )AssociationHandlerInterfacehandlerr   c                    d S r:   rK   r>   r   s     r   rs   z$AssociationHandlerInterface.set_nextJ  s	     	r@   r   r   r   r   r8   c                    d S r:   rK   r>   r   r   s      r   r   z"AssociationHandlerInterface.handleP  s    r@   Nr   r   r   r   r   )rG   rH   rI   r   rs   r   rK   r@   r   r   r   I  sR           ^
    ^  r@   r   c                  >    e Zd ZU dZded<   ddZedd            ZdS )AbstractAssociationHandlera  
    Chain of Responsibility for handling types of association, useful
    to expand in the future if we want to add more distinct associations.

    Every link of the chain checks if it's a certain type of association.
    If no association is found it's set as a generic association in `associations_type`.

    The default chaining behavior is implemented inside the base handler
    class.
    r   _next_handlerr   r   c                    || _         |S r:   )r   r   s     r   rs   z#AbstractAssociationHandler.set_nextc  s     %r@   r   r   r   r   r8   c                N    | j         r| j                             ||           d S d S r:   )r   r   r   s      r   r   z!AbstractAssociationHandler.handlei  s6     	4%%dF33333	4 	4r@   Nr   r   )rG   rH   rI   rJ   __annotations__rs   r   r   rK   r@   r   r   r   U  sb         	 	 /...    4 4 4 ^4 4 4r@   r   c                        e Zd Zd fdZ xZS )	rq   r   r   r   r   r   r8   c                   t          |j        t          j        t          j        f          r{t          |j        j        t          j        j                  rRt          |j
        |j                           }t          |t          j        |          z            |j
        |j        <   d S t                                          ||           d S r:   )r   r   r
   	AnnAssignAssignvaluer   node_classesNamer*   r   r   r~   r   r   superr   )r>   r   r   r   	__class__s       r   r   zAggregationsHandler.handlep  s    dkEOU\#BCC 	)
Kw38I
 I
 	) &24=ABBG6:%*40007 7F$T]333 GGNN4(((((r@   r   )rG   rH   rI   r   __classcell__)r   s   @r   rq   rq   o  s=        	) 	) 	) 	) 	) 	) 	) 	) 	) 	)r@   rq   c                      e Zd Zd	dZdS )
rt   r   r   r   r   r   r8   c                    t          |j        |j                           }t          |t	          j        |          z            |j        |j        <   d S r:   )r*   r   r   r~   r   r   )r>   r   r   r   s       r   r   zOtherAssociationsHandler.handle}  sG    f.t}=>>26wAQRVAWAW7W2X2X ///r@   Nr   )rG   rH   rI   r   rK   r@   r   rt   rt   |  s.        Y Y Y Y Y Yr@   rt   zno namefiles	list[str]func_wrapper_WrapperFuncTproject_name
black_listtuple[str, ...]c                *   t           j        }t          |          }| D ]s}t          j                            |          s3t           j                            |                    d                    }nBt          j        	                    |          r!t          j        
                    |d          }n|} ||j        |          }||j        p|j        |_        |                    |           |j        }	|j        r|                    d          dk    ryt           j                            t          j                            |j                  |          D ]6} ||j        |          }||j        |	k    r!|                    |           7u|S )z1Return a Project from a list of files or modules.r   z__init__.pyNr?   r   )r   MANAGERrM   r   rR   existsr   file_from_modpathr   isdirr   ast_from_filer   r_   rO   packager   get_module_filesr   )
r   r   r   r   astroid_managerrl   	somethingfpathast	base_names
             r   project_from_filesr     s    oOl##G ( (	w~~i(( 	$66ys7K7KLLEEW]]9%% 	GLLM::EEEl?8%@@ 	|/sx3H	; 	(9>>*55; 	( )::)):  ( ( #l?#@%HH #(i"7 ""3''''Nr@   )r   r   r   r   r   r   )r   r   r   r    )
r   r   r   r   r   r   r   r   r   rM   )%rJ   
__future__r   r|   r   r   r   abcr   r   collections.abcr   typingr   r   r	   r   r
   pylintr   pylint.pyreverser   r   Moduler   r   r3   r5   rM   rp   rk   r   r   rq   rt   DEFAULT_IGNORE_LISTr   rK   r@   r   <module>r     s  
 
 # " " " " "     				      # # # # # # # # % % % % % % * * * * * * * * * *              " " " " " "(C5%,#67=x?UUV
 
 
 
2 2 2 2*        V V V V V V V V:Z+ Z+ Z+ Z+ Z+u2 Z+ Z+ Z+z	 	 	 	 	# 	 	 	4 4 4 4 4!< 4 4 44
) 
) 
) 
) 
)4 
) 
) 
)Y Y Y Y Y9 Y Y Y #3!"+"?	! ! ! ! ! ! !r@   