o
    is                     @  s  d dl mZ d dlZd dl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mZ d dlmZ d dl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 d dlmZm Z m!Z! d dl"m#Z#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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 erd dl:m;Z; d dl<m=Z=m>Z> d dlm?Z? ddddZ@	 dhdhddhddhdhdhdZA	 ddhZB	 dddddddd6d2d3ZCG d4d5 d5ZDdS )7    )annotationsN)suppress)TYPE_CHECKINGFinal)get_instance_names	get_names)ast_childrenast_kindast_next)get_docstring)safe_get__all__)relative_to_absolute)get_parameters)LinesCollectionModulesCollection)KindTypeParameterKind)AliasResolutionErrorCyclicAliasErrorLastNodeError)ExprExprNamesafe_get_annotationsafe_get_base_classsafe_get_class_keywordsafe_get_conditionsafe_get_expression)
Extensionsload_extensions)Alias	AttributeClass	Decorator	DocstringFunctionModule	Parameter
Parameters	TypeAliasTypeParameterTypeParameters)Path)DocstringOptionsDocstringStyle)Parserpropertystaticmethodclassmethod)r/   r0   r1   abstractmethodcached	dataclass)zabc.abstractmethodzfunctools.cachezfunctools.cached_propertyzcached_property.cached_propertyzfunctools.lru_cachezdataclasses.dataclassztyping.overloadztyping_extensions.overload)
extensionsparentdocstring_parserdocstring_optionslines_collectionmodules_collectionmodule_namestrfilepathr+   coder5   Extensions | Noner6   Module | Noner7   DocstringStyle | Parser | Noner8   DocstringOptions | Noner9   LinesCollection | Noner:   ModulesCollection | Nonereturnr%   c          	      C  s$   t | |||pt |||||d	 S )a  Parse and visit a module file.

    We provide this function for static analysis. It uses a [`NodeVisitor`][ast.NodeVisitor]-like class,
    the [`Visitor`][griffe.Visitor], to compile and parse code (using [`compile`][])
    then visit the resulting AST (Abstract Syntax Tree).

    Important:
        This function is generally not used directly.
        In most cases, users can rely on the [`GriffeLoader`][griffe.GriffeLoader]
        and its accompanying [`load`][griffe.load] shortcut and their respective options
        to load modules using static analysis.

    Parameters:
        module_name: The module name (as when importing [from] it).
        filepath: The module file path.
        code: The module contents.
        extensions: The extensions to use when visiting the AST.
        parent: The optional parent of this module.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Returns:
        The module, with its members populated.
    )r7   r8   r9   r:   )Visitorr   
get_module)	r;   r=   r>   r5   r6   r7   r8   r9   r:    rH   e/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/griffe/_internal/agents/visitor.pyvisitP   s   &
rJ   c                      sT  e Zd ZU dZ					dhdi fddZdddjdd Zejd!kr<ej	e
jeje
jeje
jiZd"ed#< dd$dkd)d*Zndd$dld,d*Zdmd.d/Zdnd0d1Zdnd2d3Zdod5d6Zdpd8d9Zdqd=d>ZdrdAdBZdsdtdFdGZdudIdJZdvdLdMZejd!krdwdOdPZdxdRdSZdydUdVZ	dsdzdZd[Z d{d]d^Z!d|d`daZ"d}dcddZ#d~dfdgZ$  Z%S )rF   zoThis class is used to instantiate a visitor.

    Visitors iterate on AST nodes to extract data from them.
    Nr;   r<   r=   r+   r>   r5   r   r6   r@   r7   rA   r8   rB   r9   rC   r:   rD   rE   Nonec
           
        st   t    || _	 || _	 || _	 || _	 || _	 d| _	 || _	 |p$i | _		 |p+t
 | _	 |	p2t | _	 d| _dS )a$  Initialize the visitor.

        Parameters:
            module_name: The module name.
            filepath: The module filepath.
            code: The module source code.
            extensions: The extensions to use when visiting.
            parent: An optional parent for the final module object.
            docstring_parser: The docstring parser to use.
            docstring_options: Docstring parsing options.
            lines_collection: A collection of source code lines.
            modules_collection: A collection of modules.
        NF)super__init__r;   r=   r>   r5   r6   currentr7   r8   r   r9   r   r:   type_guarded)
selfr;   r=   r>   r5   r6   r7   r8   r9   r:   	__class__rH   rI   rM      s.   

zVisitor.__init__Fstrictnodeast.ASTrT   boolDocstring | Nonec                C  s4   t ||d\}}}|d u rd S t|||| j| jdS )NrS   )lineno	endlinenoparserparser_options)r   r#   r7   r8   )rP   rU   rT   valuerY   rZ   rH   rH   rI   _get_docstring   s   zVisitor._get_docstring)      z4Final[dict[type[ast.type_param], TypeParameterKind]]_type_parameter_kind_mapscopeEast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDef | ast.TypeAliasrc   
str | Nonelist[TypeParameter]c                  s    fdd|j D S )Nc                   sP   g | ]$}t |jjt| tt|d dj dtt|ddj ddqS )boundNr6   memberdefault_value)kindrg   default)r)   namera   typer   getattrrN   ).0
type_paramrc   rP   rH   rI   
<listcomp>   s    
z0Visitor._get_type_parameters.<locals>.<listcomp>)type_paramsrP   rU   rc   rH   rr   rI   _get_type_parameters   s   zVisitor._get_type_parameters5ast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDefc                C  s   g S NrH   ru   rH   rH   rI   rv      s   r%   c                 C  s.   t | jdt| jtjdd}| | | jjS )zBuild and return the object representing the module attached to this visitor.

        This method triggers a complete visit of the module nodes.

        Returns:
            A module instance.
        exec   )modefilenameflagsoptimize)	compiler>   r<   r=   astPyCF_ONLY_ASTrJ   rN   module)rP   top_noderH   rH   rI   rG      s   

zVisitor.get_modulec                 C  s    t | dt| | j| dS )ziExtend the base visit with extensions.

        Parameters:
            node: The node to visit.
        visit_N)ro   r	   generic_visitrP   rU   rH   rH   rI   rJ     s    zVisitor.visitc                 C  s   t |D ]}| | qdS )zqExtend the base generic visit with extensions.

        Parameters:
            node: The node to visit.
        N)r   rJ   )rP   rU   childrH   rH   rI   r     s   zVisitor.generic_visit
ast.Modulec              	   C  s   | j jd|| d | j jd|| d t| j| j| j| || j| jdd | _	}| j jd||| d | j jd||| d	 | 
| | j jd
||| d | j jd||| d	 dS )zWVisit a module node.

        Parameters:
            node: The node to visit.
        on_noderU   agenton_module_nodestatic)rm   r=   r6   	docstringr9   r:   analysison_instancerU   objr   on_module_instance)rU   modr   
on_memberson_module_membersN)r5   callr%   r;   r=   r6   r^   r9   r:   rN   r   )rP   rU   r   rH   rH   rI   visit_module  s    	
zVisitor.visit_moduleast.ClassDefc                   sR  j jd d j jd d g } jr+ jd j}|fdd jD  n j} fdd jD }fd	d
 jD }t j| j	
 |tj  jd ||j dd
}| j|O  _j j| |_j jd |d j jd |d   j jd |d j jd |d jj_dS )zaVisit a class definition node.

        Parameters:
            node: The node to visit.
        r   r   on_class_noder   c                 3  s.    | ]}t t| jd d|j|jdV  qdS )Fr6   parse_stringsrY   rZ   N)r"   r   rN   rY   
end_lineno)rp   decorator_noderP   rH   rI   	<genexpr>9  s    
z)Visitor.visit_classdef.<locals>.<genexpr>c                   s   g | ]}t |j jd qS )rh   )r   rN   rm   )rp   baserU   rP   rH   rI   rs   E  s    z*Visitor.visit_classdef.<locals>.<listcomp>c                   s*   i | ]}|j d ur|j t|j jdqS )Nr6   )argr   r]   rN   )rp   kwr   rH   rI   
<dictcomp>F  s    $z*Visitor.visit_classdef.<locals>.<dictcomp>rb   r   )
rm   rY   rZ   r   
decoratorstype_parametersbaseskeywordsruntimer   r   r   on_class_instance)rU   clsr   r   on_class_membersN)r5   r   decorator_listrY   extendr   r   r!   rm   r   r^   r*   rv   rO   labelsdecorators_to_labelsrN   
set_memberr   r6   )rP   rU   r   rY   r   r   class_rH   r   rI   visit_classdef,  sD   
	

zVisitor.visit_classdefr   list[Decorator]set[str]c                 C  sF   t  }|D ]}|j}|tv r|t|  q|tv r |t| O }q|S )zBuild and return a set of labels based on decorators.

        Parameters:
            decorators: The decorators to check.

        Returns:
            A set of labels.
        )setcallable_pathbuiltin_decoratorsaddstdlib_decorators)rP   r   r   	decoratorr   rH   rH   rI   r   a  s   	zVisitor.decorators_to_labelsfunctionr$   c              	   C  sj   |D ]0}z|j dd\}}W n	 ty   Y qw |dv o+||jko+| j|jd}|r2|  S qdS )a<  Check decorators to return the base property in case of setters and deleters.

        Parameters:
            decorators: The decorators to check.

        Returns:
            base_property: The property for which the setter/deleted is set.
            property_function: Either `"setter"` or `"deleter"`.
        .rz   >   setterdeleterr/   N)r   rsplit
ValueErrorpathrN   
get_memberrm   
has_labels)rP   r   r   r   r   prop_functionproperty_setter_or_deleterrH   rH   rI   get_base_propertys  s   
zVisitor.get_base_property&ast.AsyncFunctionDef | ast.FunctionDefr   
set | Nonec                   s  j jd d j jd d |pt }g }d} jrM jd j} jD ]$}t|jdd}|du r6q't||j|jd}|	| ||j
tv O }q'n j}||O }d	|v rt jdt jj jd
 j j j dd}	|	 j|O  _j j|	 j jd |	d j jd |	d dS t fddt jD  }
t j| j|
t jj jd
|tj  jd  j jdd}||}|rjj|j 	| nP|rjj j }|dkr||_|jd n8|dkr||_ |jd n)j j| jj!t"j#t"j$hv r5jj|j r5jj|j |_jj|j= | j|O  _j jd |d j jd |d jj!t"j$u rm|jdkro|_%  jj&_dS dS dS )zHandle a function definition node.

        Parameters:
            node: The node to visit.
            labels: Labels to add to the data object.
        r   r   on_function_nodeFr   r   Nr   r/   rh   r   rm   r]   
annotationrY   rZ   r   r   r   r   r   on_attribute_instancerU   attrr   c                   sL   g | ]"\}}}}t ||t|j jd t|tr|nt|jdddqS )rh   Fr   )rk   r   rl   )r&   r   rN   rm   
isinstancer<   r   )rp   rm   r   rk   rl   r   rH   rI   rs     s    
	z+Visitor.handle_function.<locals>.<listcomp>rb   )rm   rY   rZ   
parametersreturnsr   r   r   r   r6   r   r   writabler   	deletableon_function_instance)rU   funcr   rM   )'r5   r   r   r   rY   r   rN   r"   r   appendr   typing_overloadr   r    rm   r   r   r^   rO   r   r   r'   r   argsr$   r*   rv   r   	overloadsmembersr   r   r   rk   r   MODULECLASSr   r6   )rP   rU   r   r   overloadrY   r   decorator_valuer   	attributer   r   property_functionbase_propertyrH   r   rI   handle_function  s   



	
&
zVisitor.handle_functionast.FunctionDefc                 C     |  | dS )zdVisit a function definition node.

        Parameters:
            node: The node to visit.
        Nr   r   rH   rH   rI   visit_functiondef     zVisitor.visit_functiondefast.AsyncFunctionDefc                 C  s   | j |dhd dS )zkVisit an async function definition node.

        Parameters:
            node: The node to visit.
        async)r   Nr   r   rH   rH   rI   visit_asyncfunctiondef  s   zVisitor.visit_asyncfunctiondefast.TypeAliasc              
   C  s   | j jd|| d | j jd|| d |jj}t|j| j|d}z| jt|dd}W n t	t
fy7   d}Y nw t|||j|jt| j||d || jd	d
}| j|| | j jd||| d | j jd||| d dS )zgVisit a type alias node.

            Parameters:
                node: The node to visit.
            r   r   on_type_alias_noderh   TrS   Nrb   r   )rm   r]   rY   rZ   r   r   r6   r   r   r   on_type_alias_instance)rU   
type_aliasr   )r5   r   rm   idr   r]   rN   r^   r
   r   AttributeErrorr(   rY   r   r*   rv   r   )rP   rU   rm   r]   r   r   rH   rH   rI   visit_typealias  s,   
zVisitor.visit_typealias
ast.Importc              	   C  s   |j D ]A}|jr|jn|jddd }|jp|ddd }|| jj|< t|||j|j| j	 dd}| j
|| | jjd||| d qdS )	zXVisit an import node.

        Parameters:
            node: The node to visit.
        r   rz   r   r   rY   rZ   r   r   on_alias_instancealiasrU   r   N)namesasnamerm   splitrN   importsr   rY   r   rO   r   r5   r   rP   rU   rm   
alias_path
alias_namer   rH   rH   rI   visit_import,  s   
zVisitor.visit_importast.ImportFromc              	   C  s   |j D ]c}|js|jdkr|js| jjjrqt||| jj}|jdkr0|dd}|dd}n|jp5|j}|| jj	|< || jj
 d| krft|||j|j| j dd}| j|| | jjd	||| d
 qdS )z_Visit an "import from" node.

        Parameters:
            node: The node to visit.
        rz   *r   /z.* r   r   r   r   N)r   r   levelr   rN   is_init_moduler   rm   replacer   r   r   rY   r   rO   r   r5   r   r   rH   rH   rI   visit_importfromA  s,   
 
zVisitor.visit_importfromast.Assign | ast.AnnAssignr   str | Expr | Nonec                 C  s   | j jd|| d | j jd|| d | j}t }d}|jtju r7zt|}W n
 ty0   Y dS w |	d nh|jtj
u rszt|}W n
 tyM   Y dS w t|tr_|jr_|j}|	d n@|jrm|	d |	d n2|	d n,|jtju r|jdkrdS zt|}W n
 ty   Y dS w |j}|du rdS |	d |sdS t|j| jd	d
}z| jt|dd}W n ttfy   d}Y nw |D ]}d|v rq||jv r&t|jtjtjfrq|j| }	ttt4 ||	j O }|	j!r|s|	j!}tt |	j"r|s|	j"}W d   n	1 sw   Y  W d   n	1 s!w   Y  t#||||j$|j%|| j& dd}
|
 j |O  _ |'||
 |dkritt dd t(|| jD |_)W d   n	1 sdw   Y  | j jd||
| d | j jd||
| d qdS )zHandle an attribute (assignment) node.

        Parameters:
            node: The node to visit.
            annotation: A potential annotation.
        r   r   on_attribute_nodeNzmodule-attributezclass-attributezinstance-attributerM   Fr   TrS   r   r   r   __all__c                 S  *   g | ]}t |tr|nt|j|jd qS r   r   r<   r   rm   r6   rp   rm   rH   rH   rI   rs         z,Visitor.handle_attribute.<locals>.<listcomp>r   r   r   r   )*r5   r   rN   r   rk   r   r   r   KeyErrorr   r   r   r   is_classvarslicer]   FUNCTIONrm   r   r6   r   r^   r
   r   r   r   r   IfExceptHandlerr   r   r   r   r   r   r    rY   r   rO   r   r   exports)rP   rU   r   r6   r   r   r]   r   rm   existing_memberr   rH   rH   rI   handle_attributee  s   






	




zVisitor.handle_attribute
ast.Assignc                 C  r   )z\Visit an assignment node.

        Parameters:
            node: The node to visit.
        N)r  r   rH   rH   rI   visit_assign  r   zVisitor.visit_assignast.AnnAssignc                 C  s   |  |t|j| jd dS )zfVisit an annotated assignment node.

        Parameters:
            node: The node to visit.
        r   N)r  r   r   rN   r   rH   rH   rI   visit_annassign  s   zVisitor.visit_annassignast.AugAssignc                 C  s   t t4 |jjdko| jjot|jtj	}|r0| jj
dd t|| jD  W d   dS W d   dS 1 s;w   Y  dS )zfVisit an augmented assignment node.

        Parameters:
            node: The node to visit.
        r  c                 S  r  r  r  r  rH   rH   rI   rs     r  z+Visitor.visit_augassign.<locals>.<listcomp>N)r   r   targetr   rN   	is_moduler   opr   Addr  r   r   )rP   rU   all_augmentrH   rH   rI   visit_augassign  s   

"zVisitor.visit_augassignast.Ifc                 C  sL   t |jtjtjfrt|j| jdd}t|dv rd| _	| 
| d| _	dS )zVVisit an "if" node.

        Parameters:
            node: The node to visit.
        N)r6   	log_level>   typing.TYPE_CHECKINGr   TF)r   r6   r   r%   ClassDefr   testrN   r<   rO   r   )rP   rU   	conditionrH   rH   rI   visit_if  s   

zVisitor.visit_if)NNNNN)r;   r<   r=   r+   r>   r<   r5   r   r6   r@   r7   rA   r8   rB   r9   rC   r:   rD   rE   rK   )rU   rV   rT   rW   rE   rX   )rU   rd   rc   re   rE   rf   )rU   rw   rc   re   rE   rf   )rE   r%   )rU   rV   rE   rK   )rU   r   rE   rK   )rU   r   rE   rK   )r   r   rE   r   )r   r   r   r$   rE   re   rx   )rU   r   r   r   rE   rK   )rU   r   rE   rK   )rU   r   rE   rK   )rU   r   rE   rK   )rU   r   rE   rK   )rU   r  rE   rK   )rU   r  r   r  rE   rK   )rU   r  rE   rK   )rU   r  rE   rK   )rU   r!  rE   rK   )rU   r(  rE   rK   )&__name__
__module____qualname____doc__rM   r^   sysversion_infor   TypeVarr   type_varTypeVarTupletype_var_tuple	ParamSpec
param_specra   __annotations__rv   rG   rJ   r   r   r   r   r   r   r   r   r   r  r
  r  r  r   r'  r.  __classcell__rH   rH   rQ   rI   rF      sL   
 <





	

5

j

	

$
'
k

rF   )r;   r<   r=   r+   r>   r<   r5   r?   r6   r@   r7   rA   r8   rB   r9   rC   r:   rD   rE   r%   )E
__future__r   r   r3  
contextlibr   typingr   r   )griffe._internal.agents.nodes.assignmentsr   r   !griffe._internal.agents.nodes.astr   r	   r
   (griffe._internal.agents.nodes.docstringsr   %griffe._internal.agents.nodes.exportsr   %griffe._internal.agents.nodes.importsr   (griffe._internal.agents.nodes.parametersr   griffe._internal.collectionsr   r   griffe._internal.enumerationsr   r   griffe._internal.exceptionsr   r   r   griffe._internal.expressionsr   r   r   r   r   r   r    griffe._internal.extensions.baser   r   griffe._internal.modelsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   pathlibr+   #griffe._internal.docstrings.parsersr,   r-   r.   r   r   r   rJ   rF   rH   rH   rH   rI   <module>   sX   $	83