
    g[c                       d dl m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 d dlmZmZ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/m0Z0m1Z1m2Z2m3Z3 erd dl4m5Z5 d dlm6Z6 ddddZ7	 dhdhddhddhdhdhdZ8	 ddhZ9	 ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ: G d d       Z;y)"    )annotationsN)suppress)TYPE_CHECKINGAny)get_instance_names	get_names)ast_childrenast_kindast_next)get_docstring)safe_get__all__)relative_to_absolute)get_parameters)LinesCollectionModulesCollection)Kind)AliasResolutionErrorCyclicAliasErrorLastNodeError)ExprExprNamesafe_get_annotationsafe_get_base_classsafe_get_conditionsafe_get_expression)
Extensionsload_extensions)	Alias	AttributeClass	Decorator	DocstringFunctionModule	Parameter
Parameters)Path)Parserpropertystaticmethodclassmethod)r)   r*   r+   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_collectionc               ^    t        | |||xs
 t               |||||	      j                         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: Additional docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Returns:
        The module, with its members populated.
    )r1   r2   r3   r4   )Visitorr   
get_module)	module_namefilepathcoder/   r0   r1   r2   r3   r4   s	            K/var/www/openai/venv/lib/python3.12/site-packages/_griffe/agents/visitor.pyvisitr<   @   s>    L 'o')+)-
 jl
    c                       e Zd ZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddddZddZddZddZdd	Z	dd
Z
ddZddZd d!dZd"dZd#dZd$dZd%dZ	 d 	 	 	 	 	 d&dZd'dZd(dZd)dZd*dZ xZS )+r6   zoThis class is used to instantiate a visitor.

    Visitors iterate on AST nodes to extract data from them.
    c
                   t         
|           || _        	 || _        	 || _        	 || _        	 || _        	 d| _        	 || _        	 |xs i | _	        	 |xs
 t               | _        	 |	xs
 t               | _        	 d| _        y)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: The docstring parsing options.
            lines_collection: A collection of source code lines.
            modules_collection: A collection of modules.
        NF)super__init__r8   r9   r:   r/   r0   currentr1   r2   r   r3   r   r4   type_guarded)selfr8   r9   r:   r/   r0   r1   r2   r3   r4   	__class__s             r;   rA   zVisitor.__init__y   s    2 	 +&"	%&0:%+='+//?*1B1Hb,1A1V_EV05G5^K\K^&"'>r=   Fstrictc               r    t        ||      \  }}}|y t        |||| j                  | j                        S )NrF   )lineno	endlinenoparserparser_options)r   r"   r1   r2   )rD   noderG   valuerI   rJ   s         r;   _get_docstringzVisitor._get_docstring   sE    #0f#E vy=((11
 	
r=   c                    t        | j                  dt        | j                        t        j
                  d      }| j                  |       | 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:   strr9   astPyCF_ONLY_ASTr<   rB   module)rD   top_nodes     r;   r7   zVisitor.get_module   sG     4996C<NVYVgVgrst

8||"""r=   c                V     t        | dt        |       | j                        |       y)ziExtend the base visit with extensions.

        Parameters:
            node: The node to visit.
        visit_N)getattrr
   generic_visitrD   rM   s     r;   r<   zVisitor.visit   s*     	Ex~./1C1CDTJr=   c                F    t        |      D ]  }| j                  |        y)zqExtend the base generic visit with extensions.

        Parameters:
            node: The node to visit.
        N)r	   r<   )rD   rM   childs      r;   r`   zVisitor.generic_visit   s     "$'EJJu (r=   c                H   | j                   j                  d||        | j                   j                  d||        t        | j                  | j                  | j
                  | j                  |      | j                  | j                        x| _	        }| j                   j                  d|||        | j                   j                  d|||        | j                  |       | j                   j                  d	|||        | j                   j                  d
|||        y)zWVisit a module node.

        Parameters:
            node: The node to visit.
        on_noderM   agenton_module_node)namer9   r0   	docstringr3   r4   on_instancerM   objrg   on_module_instance)rM   modrg   
on_memberson_module_membersN)r/   callr$   r8   r9   r0   rO   r3   r4   rB   r`   )rD   rM   r[   s      r;   visit_modulezVisitor.visit_module   s     	YT>-DE &!!]];;))$/!22#66!
 	
v 	]6N1&PTU4 \&M0ttTr=   c           	          j                   j                  d|         j                   j                  d|        g }|j                  r>|j                  d   j                  }|j	                   fd|j                  D               n|j                  }|j
                  D cg c]  }t        | j                         }}t        |j                  ||j                   j                  |      || j                         }|xj                   j                  |      z  c_         j                  j                  |j                  |       | _         j                   j                  d|| 	        j                   j                  d
||         j!                  |        j                   j                  d|| 	        j                   j                  d||         j                  j"                   _        yc c}w )zaVisit a class definition node.

        Parameters:
            node: The node to visit.
        re   rf   on_class_noder   c              3     K   | ]<  }t        t        |j                  d       |j                  |j                         > yw)Fr0   parse_stringsrI   rJ   N)r!   r   rB   rI   
end_lineno).0decorator_noderD   s     r;   	<genexpr>z)Visitor.visit_classdef.<locals>.<genexpr>  sJ       ':N 't||[`a)00,77 
 ':s   AAr0   )ri   rI   rJ   rj   
decoratorsbasesruntimerk   rl   on_class_instance)rM   clsrg   rp   on_class_membersN)r/   rr   decorator_listrI   extendr   r   rB   r    ri   rz   rO   rC   labelsdecorators_to_labels
set_memberr`   r0   )rD   rM   r   rI   baser   class_s   `      r;   visit_classdefzVisitor.visit_classdef   s    	YT>_4tD ')
((+22F  '+&9&9  [[F MQJJWJD$T$,,?JWoo))$/!)))
 	22:>>		62]6N0ttT4 \&M/ddS||**' Xs   $G>c                    t               }|D ]D  }|j                  }|t        v r|j                  t        |          0|t        v s9|t        |   z  }F |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)rD   r   r   	decoratorr   s        r;   r   zVisitor.decorators_to_labels$  s[     #I%33M 22

-m<="33+M:: $ r=   c                   |D ]s  }	 |j                   j                  dd      \  }}|dv xrE ||j                  k(  xr4 | j                  j                  |j                        j                  d      }|sq|c S  y# t        $ r Y w xY w)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"`.
        .rR   >   setterdeleterr)   N)r   rsplit
ValueErrorpathrB   
get_memberri   
has_labels)rD   r   functionr   r   prop_functionproperty_setter_or_deleters          r;   get_base_propertyzVisitor.get_base_property6  s     $I&/&=&=&D&DS!&L#m !66 RHMM)RLL++HMM:EEjQ '
 *$$ $   s   A::	BBc                H
   | j                   j                  d||        | j                   j                  d||        |xs
 t               }g }d}|j                  r|j                  d   j                  }|j                  D ]e  }t        || j                  d      }|t        ||j                  |j                        }|j                  |       ||j                  t        v z  }g n|j                  }|| j                  |      z  }d	|v rt        |j                  dt        |j                   | j                  
      |j                  |j                  | j#                  |      | j$                         }	|	xj&                  |z  c_        | j                  j)                  |j                  |	       | j                   j                  d||	|        | j                   j                  d||	|        yt+        t-        |j.                        D 
cg c]S  \  }
}}}t1        |
|t        || j                  
      t3        |t4              r|nt        || j                  d            U c}}}}
 }t7        |j                  ||j                  |t        |j                   | j                  
      || j#                  |      | j$                   | j                  	      }| j9                  ||      }|r4| j                  j:                  |j                     j                  |       n=|rs| j                  j<                  |j                     }|dk(  r#||_        |j&                  jA                  d       n|dk(  r||_!        |j&                  jA                  d       n| j                  j)                  |j                  |       | j                  jD                  tF        jH                  tF        jJ                  hv rl| j                  j:                  |j                     rI| j                  j:                  |j                     |_        | j                  j:                  |j                  = |xj&                  |z  c_        | j                   j                  d|||        | j                   j                  d|||        | j                  jD                  tF        jJ                  u rD|j                  dk(  r4|| _        | jM                  |       | j                  jN                  | _        yyyc c}}}}
w )zHandle a function definition node.

        Parameters:
            node: The node to visit.
            labels: Labels to add to the data object.
        re   rf   on_function_nodeFr   rw   Nry   r)   r~   ri   rN   
annotationrI   rJ   rj   r   rk   rl   on_attribute_instancerM   attrrg   )kindr   default)	ri   rI   rJ   
parametersreturnsr   rj   r   r0   r   writabler   	deletableon_function_instance)rM   funcrg   rA   )(r/   rr   r   r   rI   r   rB   r!   rz   appendr   typing_overloadr   r   ri   r   r   rO   rC   r   r   r&   r   argsr%   
isinstancerX   r#   r   	overloadsmembersr   r   r   r   r   MODULECLASSr`   r0   )rD   rM   r   r   overloadrI   r|   decorator_valuer   	attributeri   r   r   r   r   r   property_functionbase_propertys                     r;   handle_functionzVisitor.handle_functionN  sC    	YT>/d$G35 
((+22F"&"5"5"5nT\\in"o"*%#)00,77	
 !!),I33FF #6 [[F$++J77!YY.t||DLLQ{{//--d3 ---I &LL##DIIy9OO  TyPT UOO  !8t)[_ `   8Fdii7P
 8Q3D*dG 2:dllS!'3/ $,WT\\Y^_ 8Q


 oo!'T\\J!))$/)))<<

 !22:xHLL""8==188B'+||';';DII'FM H,'/$$$((4"i/(0%$$((5LL##DIIx8||  T[[$**$==$,,BXBXYaYfYfBg%)\\%;%;HMM%J"LL**8==96!]84P3$XUYZ<<

*x}}
/J#DLt$<<..DL 0K*_
s   ATc                &    | j                  |       y)zdVisit a function definition node.

        Parameters:
            node: The node to visit.
        Nr   ra   s     r;   visit_functiondefzVisitor.visit_functiondef  s     	T"r=   c                ,    | j                  |dh       y)zkVisit an async function definition node.

        Parameters:
            node: The node to visit.
        async)r   Nr   ra   s     r;   visit_asyncfunctiondefzVisitor.visit_asyncfunctiondef  s     	T7)4r=   c                   |j                   D ]  }|j                  r|j                  n|j                  j                  dd      d   }|j                  xs |j                  dd      d   }|| j                  j
                  |<   t        |||j                  |j                  | j                         }| j                  j                  ||       | j                  j                  d|||         y)zXVisit an import node.

        Parameters:
            node: The node to visit.
        r   rR   r   rI   rJ   r   on_aliasaliasrM   rg   N)namesasnameri   splitrB   importsr   rI   rz   rC   r   r/   rr   rD   rM   ri   
alias_path
alias_namer   s         r;   visit_importzVisitor.visit_import  s     JJD&*kktyysA7Nq7QJC
(8(8a(@(CJ/9DLL  ,{{// ---E LL##J6OO  5t4 P r=   c                   |j                   D ]\  }|j                  s<|j                  dk(  r-|j                  s!| j                  j                  j
                  rLt        ||| j                  j                        }|j                  dk(  r%|j                  dd      }|j                  dd      }n3|j                  xs |j                  }|| j                  j                  |<   || j                  j                   d| k7  st        |||j                  |j                  | j                         }| j                  j                  ||       | j                   j#                  d||| 	       _ y
)z_Visit an "import from" node.

        Parameters:
            node: The node to visit.
        rR   *r   /z.* r   r   r   N)r   r[   levelr   rB   is_init_moduler   ri   replacer   r   r   rI   rz   rC   r   r/   rr   r   s         r;   visit_importfromzVisitor.visit_importfrom  s)    JJD;;4::?4;;4<<K^K^KmKm
 -dD$,,:M:MNJyyC'//S9
'//b9
![[5DII
3=$$Z0  1 12!J<@@;;"oo $ 1 11 ''
E:$$Zu4t$T7 r=   c           
     :   | j                   j                  d||        | j                   j                  d||        | j                  }t               }|j                  t
        j                  u r	 t        |      }|j                  d       n|j                  t
        j                  u r	 t        |      }t        |t              r*|j                  r|j                  }|j                  d       n|j                  r#|j                  d       |j                  d       ng|j                  d       nU|j                  t
        j                   u r9|j"                  dk7  ry	 t%        |      }|j&                  }|j                  d       syt)        |j                  | j                  d	
      }	 | j+                  t-        |      d      }|D ]  }d|v r	||j2                  v rt        |j&                  t4        j6                  t4        j8                  f      rL|j2                  |   }	t;        t<        t>              5  ||	j@                  z  }|	jB                  r|s|	jB                  }t;        t0              5  |	jD                  r|s|	jD                  }ddd       ddd       tG        ||||jH                  |jJ                  || jL                         }
|
xj@                  |z  c_         |jO                  ||
       |dk(  rrt;        t0              5  tQ        || j                        D cg c]5  }t        |tR              r|n tU        |j"                  |j&                        7 c}|_+        ddd       | j                   j                  d||
|        | j                   j                  d||
|         y# t        $ r Y yw xY w# t        $ r Y yw xY w# t        $ r Y yw xY w# t.        t0        f$ r d}Y 'w xY w# 1 sw Y   hxY w# 1 sw Y   mxY wc c}w # 1 sw Y   xY w)zHandle an attribute (assignment) node.

        Parameters:
            node: The node to visit.
            annotation: A potential annotation.
        re   rf   on_attribute_nodeNzmodule-attributezclass-attributezinstance-attributerA   Frw   TrF   r   r   __all__r~   rk   rl   r   r   ),r/   rr   rB   r   r   r   r   r   KeyErrorr   r   r   r   is_classvarslicerN   FUNCTIONri   r   r0   r   rO   r   r   AttributeErrorr   rY   IfExceptHandlerr   r   r   r   rj   r   r   rI   rz   rC   r   r   rX   r   exports)rD   rM   r   r0   r   r   rN   rj   ri   existing_memberr   s              r;   handle_attributezVisitor.handle_attribute  s    	YT>0t4H;;$++%!$ JJ)*[[DJJ&!$ *d+
0F0F'--


,-

,-

/0 

/0[[DMM){{j(*40 ]]FJJ+,#DJJt||SXY	++HTN4+HI D d{v~~% dkkCFFC4E4E+FG"(.."624DEo444F&00$3$=$=	!.1*55j)8)C)CJ 2 F "%{{//# ---I &dI.y n- %4D$,,$G&$GD !+4 58DIIVZVaVa;bb$G&FN .
 OO  TyPT UOO  !8t)[_ `S S    (   ~. 	I	* 21 FE.& .-s   0N- *N< O +O 89O?1O2O?P!:PP-	N98N9<	OO	OOO/.O/2O<7O??P		PP	c                &    | j                  |       y)z\Visit an assignment node.

        Parameters:
            node: The node to visit.
        N)r   ra   s     r;   visit_assignzVisitor.visit_assignc  s     	d#r=   c                f    | j                  |t        |j                  | j                               y)zfVisit an annotated assignment node.

        Parameters:
            node: The node to visit.
        r~   N)r   r   r   rB   ra   s     r;   visit_annassignzVisitor.visit_annassignk  s'     	d$7PTP\P\$]^r=   c           
        t        t              5  |j                  j                  dk(  xr< | j                  j
                  xr$ t        |j                  t        j                        }|rx| j                  j                  j                  t        || j                        D cg c]5  }t        |t              r|n t        |j                  |j                         7 c}       ddd       yc c}w # 1 sw Y   yxY w)zfVisit an augmented assignment node.

        Parameters:
            node: The node to visit.
        r   r~   N)r   r   targetidrB   	is_moduler   oprY   Addr   r   r   rX   r   ri   r0   )rD   rM   all_augmentri   s       r;   visit_augassignzVisitor.visit_augassigns  s     n%)+ 1LL**1tww0 
 $$++ %4D$,,$G$GD !+4 58DIIVZVaVa;bb$G &% &%s   BC0!:C+
C0+C00C9c                   t        |j                  t        j                  t        j                  f      r6t        |j                  | j                  d      }t        |      dv rd| _	        | j                  |       d| _	        y)zVVisit an "if" node.

        Parameters:
            node: The node to visit.
        N)r0   	log_level>   typing.TYPE_CHECKINGr   TF)r   r0   rY   r$   ClassDefr   testrB   rX   rC   r`   )rD   rM   	conditions      r;   visit_ifzVisitor.visit_if  sa     dkkCJJ#=>*499T\\UYZI9~!JJ$(!4 !r=   )NNNNN)r8   rX   r9   r'   r:   rX   r/   r   r0   Module | Noner1   Parser | Noner2   dict[str, Any] | Noner3   LinesCollection | Noner4   ModulesCollection | NonereturnNone)rM   ast.ASTrG   boolr   zDocstring | None)r   r$   )rM   r   r   r   )rM   z
ast.Moduler   r   )rM   zast.ClassDefr   r   )r   list[Decorator]r   zset[str])r   r  r   r#   r   z
str | None)N)rM   z&ast.AsyncFunctionDef | ast.FunctionDefr   z
set | Noner   r   )rM   zast.FunctionDefr   r   )rM   zast.AsyncFunctionDefr   r   )rM   z
ast.Importr   r   )rM   zast.ImportFromr   r   )rM   zast.Assign | ast.AnnAssignr   zstr | Expr | Noner   r   )rM   z
ast.Assignr   r   )rM   zast.AnnAssignr   r   )rM   zast.AugAssignr   r   )rM   zast.Ifr   r   )__name__
__module____qualname____doc__rA   rO   r7   r<   r`   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)rE   s   @r;   r6   r6   s   s    !%*.37377;:?:? :? 	:?
 :? :? (:? 1:? 1:? 5:? 
:?x ?D 

#KU,,+\$0e/N#5Q(!UL )-ea(ea &ea 
	eaN$_*"r=   r6   )r8   rX   r9   r'   r:   rX   r/   zExtensions | Noner0   r   r1   r   r2   r   r3   r   r4   r   r   r$   )<
__future__r   rY   
contextlibr   typingr   r    _griffe.agents.nodes.assignmentsr   r   _griffe.agents.nodes.astr	   r
   r   _griffe.agents.nodes.docstringsr   _griffe.agents.nodes.exportsr   _griffe.agents.nodes.importsr   _griffe.agents.nodes.parametersr   _griffe.collectionsr   r   _griffe.enumerationsr   _griffe.exceptionsr   r   r   _griffe.expressionsr   r   r   r   r   r   _griffe.extensions.baser   r   _griffe.modelsr   r   r    r!   r"   r#   r$   r%   r&   pathlibr'   r(   r   r   r   r<   r6    r=   r;   <module>r     s>   # 
  % J 
 : 8 = : B % T T  @ q q q+ "  
 / ,, z"*J!7(0*'=$:)]  8$&BC %) &*/3/337000 0
 "0 0 $0 -0 -0 10 0f`" `"r=   