o
    b>                     @   s  d Z ddlZddlmZmZ ddlZddlZddlZddlZddl	Z	ddl
mZmZmZmZmZmZmZmZmZ ddlZddlZddlmZ ddlmZ ddlmZ ejZejejejej fZ!ej"d dkZ#e#skd	Z$nd
Z$h dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dddddddZ/dd e/0 D Z1e2e1Z3G dd de4Z5d d! Z6d"ej7j8d#e9fd$d%Z:d"ej7j8d#eej7j8 fd&d'Z;d"ej7j8d#ee9ee<e<f f fd(d)Z=d"ej7j8d#e9fd*d+Z>d"ej7j8d#e9fd,d-Z?ej@A Zd.ZBd"ej7j8d#e9fd/d0ZCd1e<d#e9fd2d3ZDd4ej7j8d5e<d6ej7j8d#e9fd7d8ZEd4ej7j8d#e9fd9d:ZFd"ej7j8d#e9fd;d<ZGd"ej7j8d#e9fd=d>ZHd?ej7j8d"ej7j8d#e9fd@dAZId"ej7j8d#ej7j8fdBdCZJdDej7j8d1e<d#e9fdEdFZKdGe<d#efdHdIZLG dJdK dKe4ZMG dLdM dMe4ZNdNe<d#eee< eOee<e<f ee< f fdOdPZPd#ee<eee9e<f  f fdQdRZQd#eee<  fdSdTZRdNe<d#eeee<eee9e<f  f  eOeOf fdUdVZSdWe<d#e9fdXdYZTd"ej7j8d#eej7j8 fdZd[ZUdWe<d#eee<  fd\d]ZV	dd^ejWd_eOd`e<d#ejXfdadbZYd"ej7j8d#e9fdcddZZdeej[d#e9fdfdgZ\d"ej]d#e9fdhdiZ^djejXd#e9fdkdlZ_dmej]dnee< d#e9fdodpZ`edqdr	dd"ej7j8dsej]d#ee<ej7j8f fdtduZad"ej7j8d#eej[ejbf fdvdwZcd"ej7j8d#e9fdxdyZddzej[d#e9fd{d|Zee4fd"ej7j8d#eej[ fd}d~Zfd"ejgd#e9fddZhe4fd"ej7j8d#e9fddZid"ejjd#e9fddZkdej7j8de<d#e9fddZld"ej7j8d#e9fddZmdej7j8d#e9fddZndej7j8d#e9fddZodej7j8d#e9fddZpdej7j8d#e9fddZqdej7j8d#e9fddZrdej7j8d#e9fddZsdej7j8d#e9fddZtd1e<d#e9fddZud"ej7j8d#e9fddZvdej7j8dej]d#e9fddZwddej7j8de9d#e9fddZxdej7j8d#e9fddZydej7j8d#e9fddZzdej7j8d#e9fddZ{dej7j8d#e9fddZ|dej7j8d#e9fddZ}edqdr	dd"ej7j8d#eej7j8 fddZ~ddejjd#e9fddZd"ej7j8d#e9fddZd"ej7j8d#ee fddZd"ej]d#e9fddZd"ej7j8d#eOfddZd"ej7j8d#e9fddZdejjdejjd#e9fddZdS )z7some functions that may be useful for various checkers
    N)	lru_cachepartial)	OptionalIterableTupleCallableSetUnionMatchDictList)_NonDeducibleTypeHierarchy)bases)scoped_nodes   
exceptionsbuiltins>   abc.abstractmethodabc.abstractpropertyabc.abstractclassmethodabc.abstractstaticmethod__iter__	__aiter____next____getitem____class_getitem____setitem____delitem____contains__keys)__new____init____call__)&__del____repr____str__	__bytes____hash____bool____dir____len____length_hint__r   __reversed____neg____pos____abs__
__invert____complex____int__	__float__r-   r.   r/   r1   r2   r3   	__index__	__enter__
__aenter____getnewargs_ex____getnewargs____getstate__
__reduce____copy____unicode____nonzero__	__await__r   	__anext__
__fspath__)<
__format____lt____le____eq____ne____gt____ge____getattr____getattribute____delattr__
__delete____instancecheck____subclasscheck__r   __missing__r   r   __add____sub____mul____truediv____floordiv____mod__
__divmod__
__lshift__
__rshift____and____xor____or____radd____rsub____rmul____rtruediv____rmod____rdivmod____rpow____rlshift____rrshift____rand____rxor____ror____iadd____isub____imul____itruediv____ifloordiv____imod____ilshift____irshift____iand____ixor____ior____ipow____setstate____reduce_ex____deepcopy__Z__cmp__
__matmul____rmatmul__Z__div__)__setattr____get____set__r   __set_name__)__exit__	__aexit__)	__round__)Nr         r   )r   r   c                 C   s    i | ]\}}|D ]}||qqS  r   ).0paramsmethodsnamer   r   T/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/checkers/utils.py
<dictcomp>   s    r   c                   @   s   e Zd ZdS )NoSuchArgumentErrorN)__name__
__module____qualname__r   r   r   r   r      s    r   c                 C   s>   | }|rt |jtjs|j}|rt |jtjr|o||jju S )z=Returns true if node is inside the name of an except handler.)
isinstanceparentastroidExceptHandlerr   )nodecurrentr   r   r   is_inside_except   s
   r   r   returnc                 C   s0   | j }|durt|tjrdS |j }|dusdS )z*Return true if given node is inside lambdaNTF)r   r   r   Lambdar   r   r   r   r   is_inside_lambda   s   r   c                 c   sB    t | tjtjfr| jD ]}t|D ]}|V  qqdS | V  dS )z9Recursively returns all atoms in nested lists and tuples.N)r   r   r   r   eltsget_all_elements)r   childer   r   r   r      s   

r   c                 C   s   t | tjrd| jd| j f ffS t | tjrI| j}t|r&d|dffS | 	|d }|rIt |d 
 tjtjtjfsId|d|d j ffS dS )zChecks if an assignment node in an except handler clobbers an existing
    variable.

    Returns (True, args for W0623) if assignment clobbers an existing variable,
    (False, None) otherwise.
    Tz	object %rr   r   r   zouter scope (line %s))FN)r   r   Z
AssignAttrattrnameexpr	as_string
AssignNamer   
is_builtinlookupZassign_typeAssign	AugAssignr   
fromlineno)r   r   Zstmtsr   r   r   clobber_in_except   s   	
r   c                 C   s&   t | dddkr|  jtkrdS dS )zHreturn True if the node is referencing the "super" builtin function
    r   NsuperTF)getattrrootr   BUILTINS_NAMEr   r   r   r   is_super  s   r   c                 C   s$   |   D ]}t|tjr dS qdS )zAreturn true if the function does nothing but raising an exceptionTF)Zget_childrenr   r   Raise)r   
child_noder   r   r   is_error  s
   r   )__builtins__c                 C   s   | o|   jtkS )zHReturns True if the given node is an object from the __builtin__ module.)r   r   r   r   r   r   r   is_builtin_object  s   r   r   c                 C   s   | t v p| tv S )zMreturn true if <name> could be considered as a builtin defined by python
    )r   SPECIAL_BUILTINS)r   r   r   r   r   !  s   r   var_nodevarnamescopec                    s  t |tjr.|jD ]"}t |tjrt fdd|jD s(t |tjr+ |jv r+ dS q	dS t |t	tj
frI|tjD ]
}|j krF dS q<dS t |tjrq|jD ]\}}|| r^ dS |rnt |tjrn|j krn dS qRdS t |tjtjfr|j r|j| rz|j  |j}t|  | W dS  tjy   Y dS w dS t|dd  krdS dS t |tjrt |jtjr|j}|j krdS dS )Nc                 3   s&    | ]}t |tjo|j kV  qd S N)r   r   r   r   )r   targetr   r   r   	<genexpr>0  s
    
z&is_defined_in_scope.<locals>.<genexpr>Tr   F)r   r   Ifbodyr   anytargetsNonlocalnamesCOMP_NODE_TYPESFornodes_of_classr   r   WithitemsZ	parent_ofr   FunctionDefargsis_argumentdefault_valuer   is_defined_in_scopeZ	NoDefaultr   r   )r   r   r   r   Zass_noder   idsr   r   r   r   '  sh   





r   c                 C   s   | j }| j}|rt| ||rdS |j}|s|  }| }|j}|r\|j|kr\|tjD ]
}|j |kr7 dS q-|tj	tj
fD ]}|dd |jD v rP dS qA| }|r\|j|ks'dS )zreturn True if the variable node is defined by a parent node (list,
    set, dict, or generator comprehension, lambda) or in a previous sibling
    node on the same line (statement_defining ; statement_using)
    Tc                 S   s   g | ]
}|d  p|d qS )r   r   r   )r   r   r   r   r   
<listcomp>k  s    z%is_defined_before.<locals>.<listcomp>F)r   r   r   Z	statementZprevious_siblingr   r   r   r   
ImportFromImportr   )r   r   _nodestmtlinenoZassign_nodeZimp_noder   r   r   is_defined_beforeW  s,   
r   c                 C   sN   |   }t|tjtjfr%|jjD ]}|tjD ]
}|| u r#  dS qqdS )zbreturn true if the given Name node is used in function or lambda
    default argument's value
    TF)	r   r   r   r   r   r   defaultsr   Name)r   r   default_nodeZdefault_name_noder   r   r   is_default_argumentq  s   r   c                 C   sR   | j }|dur't|tjrdS |jst|tjtjtjfr 	 dS |j }|dusdS )z5return true if the name is used in function decoratorNTF)	r   r   r   Z
DecoratorsZis_statementr   r   ZComprehensionScopeListCompr   r   r   r   is_func_decorator~  s   	r   framec                 C   sD   z| j }W n
 ty   Y dS w |D ]}||tjv r dS qdS )zjreturn True if `frame` is an astroid.Class node with `node` in the
    subtree of its bases attribute
    FT)r   AttributeErrorr   r   r   )r   r   r   baser   r   r   is_ancestor_name  s   
r   c                 C   s>   | rt | tjtjtjfr| j} | rt | tjtjtjfs| S )zLreturn the higher parent which is not an AssignName, Tuple or List node
    )r   r   r   r   r   r   r   r   r   r   assign_parent  s   r   
class_nodec                 C   s0   |   D ]}||v rt|| tjr dS qdS )z=return True if <name> is a method overridden from an ancestorTF)	ancestorsr   r   r   )r   r   ancestorr   r   r   overrides_a_method  s
   r   messagesc                     s    fdd}|S )z@decorator to store messages that are handled by a checker methodc                    s
    | _ | S r   )Zchecks_msgs)funcr   r   r   store_messages  s   z&check_messages.<locals>.store_messagesr   )r   r   r   r   r   check_messages  s   r   c                   @   s   e Zd ZdZdS )IncompleteFormatStringz:A format string ended in the middle of a format specifier.N)r   r   r   __doc__r   r   r   r   r     s    r   c                   @   s   e Zd ZdZdd ZdS )UnsupportedFormatCharacterzXA format character in a format string is not one of the supported
    format characters.c                 C   s   t | | || _d S r   )	Exceptionr!   index)selfr   r   r   r   r!     s   
z#UnsupportedFormatCharacter.__init__N)r   r   r   r   r!   r   r   r   r   r     s    r   format_stringc                    s  t  }t }g }d} fdd}d}|t k r | }|dkr||\}}d}|dkr_d}	||\}}|}
|	dkrU|dkrC|	d7 }	n|dkrK|	d8 }	||\}}|	dks:|d } |
| }|d	v rm||\}}|d	v sc|d
kr||d7 }||\}}n|tjv r||\}}|tjv s|dkr||\}}|d
kr|d7 }||\}}n|tjv r||\}}|tjv s|dv r||\}}trd}nd}||vrt||r|| |||< n|dkr|d7 }|| |d7 }|t k s||||fS )a'  Parses a format string, returning a tuple of (keys, num_args), where keys
    is the set of mapping keys in the format string, and num_args is the number
    of arguments required by the format string.  Raises
    IncompleteFormatString or UnsupportedFormatCharacter if a
    parse error occurs.r   c                    s$   | d7 } | t  krt|  |  fS )Nr   )lenr   )ir   r   r   	next_char  s   z&parse_format_string.<locals>.next_char%N(r   )z#0- +*.ZhlLzdiouxXeEfFgGcrs%azdiouxXeEfFgGcrs%)	setdictr   stringdigitsPY3Kr   addappend)r   r   Z	key_typesZ	pos_typesnum_argsr   r   charkeydepthZ	key_startZkey_endflagsr   r   r   parse_format_string  sr   







7r   c                 C   s"   zt | W S  ty   t w r   )_stringformatter_field_name_split
ValueErrorr   r   r   r   r   split_format_field_names  s
   r  c              
   c   s    t  }z2|| }|D ]'}tdd |dd D rq|d }|d }|V  |r4t|D ]}|V  q.qW dS  ty\ } z|jd drTdV  d	V  W Y d}~dS t| d}~ww )
zy Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.
    c                 s   s    | ]}|d u V  qd S r   r   )r   itemr   r   r   r   "      z(collect_string_fields.<locals>.<genexpr>r   Nr   r   zcannot switch from manual 1)	r   	Formatterparseallcollect_string_fieldsr  r   
startswithr   )r   	formatterZparseiteratorresultr   nestedfieldexcr   r   r   r    s.   

r  c              	   C   s   g }d}t  }t| D ]E}|rt| r|t| q|rLt|\}}t|tjr6|t| t	|}z|
|t|f W q tyK   t w |d7 }q||t|fS )aq  
    Parses a PEP 3101 format string, returning a tuple of
    (keyword_arguments, implicit_pos_args_cnt, explicit_pos_args),
    where keyword_arguments is the set of mapping keys in the format string, implicit_pos_args_cnt
    is the number of arguments required by the format string and
    explicit_pos_args is the number of arguments passed with the position.
    r   r   )r   r  strisdigitr   r  r   numbersNumberintr   listr  r   r   )r   Zkeyword_argumentsZimplicit_pos_args_cntZexplicit_pos_argsr   ZkeynameZfielditeratorr   r   r   parse_format_method_string:  s$   

r  r   c                 C   s*   | d dko| dko|  do| d S )zkreturn True if attribute name is protected (start with _ and some other
    details), False otherwise.
    r   ___)r  endswith)r   r   r   r   is_attr_protectedZ  s
   r  c                 C   sN   |   }|dur%t|tjs%|jdu rd}n|j  }|dur%t|tjr|S )zhreturn klass node for a method node (or a staticmethod or a
    classmethod), return null otherwise
    N)r   r   r   ClassDefr   )r   klassr   r   r   node_frame_classe  s   

r   c                 C   s   t d}|| S )zqCheck that attribute name is private (at least two leading underscores,
    at most one trailing underscore)
    z^_{2,}.*[^_]+_?$)recompilematch)r   regexr   r   r   is_attr_privatev  s   

r%  	call_nodepositionkeywordc                 C   sn   |du r|du rt d|dur z| j| W S  ty   Y nw |r5| jr5| jD ]}|j|kr4|j  S q(t)a
  Returns the specified argument from a function call.

    :param astroid.Call call_node: Node representing a function call to check.
    :param int position: position of the argument.
    :param str keyword: the keyword of the argument.

    :returns: The node representing the argument, None if the argument is not found.
    :rtype: astroid.Name
    :raises ValueError: if both position and keyword are None.
    :raises NoSuchArgumentError: if no argument at the provided position or with
    the provided keyword.
    Nz2Must specify at least one of: position or keyword.)r  r   
IndexErrorkeywordsargvaluer   )r&  r'  r(  r+  r   r   r   get_argument_from_call~  s   



r-  c                 C   sD   | j dv r|  j tkrdS t| dsdS tdd | jddD S )zV
    Return true if the given class node is subclass of
    exceptions.Exception.
    )r   BaseExceptionTr   Fc                 s   s    | ]}t |V  qd S r   )inherit_from_std_ex)r   r   r   r   r   r     r  z&inherit_from_std_ex.<locals>.<genexpr>)Zrecurs)r   r   EXCEPTIONS_MODULEhasattrr   r   r   r   r   r   r/    s   
r/  handlerc                    s>   dd  t |ts|f} fdd|D }| jsdS | |S )ar  
    Check if the given exception handler catches
    the given error_type.

    The *handler* parameter is a node, representing an ExceptHandler node.
    The *error_type* can be an exception, such as AttributeError,
    the name of an exception, or it can be a tuple of errors.
    The function will return True if the handler catches any of the
    given errors.
    c                 S   s   t | ts| jS | S r   )r   r  r   )errorr   r   r   stringify_error  s   
z&error_of_type.<locals>.stringify_errorc                    s   h | ]} |qS r   r   )r   r3  r4  r   r   	<setcomp>  s    z error_of_type.<locals>.<setcomp>T)r   tupletypeZcatch)r2  
error_typeZexpected_errorsr   r5  r   error_of_type  s   

r:  c              	   C   sR   | j sdS | j jD ]}t|tjsq	z
t|rW  dS W q	 tjy&   Y q	w dS )zA Detect if the given function node is decorated with a property. FT)
decoratorsnodesr   r   r   _is_property_decoratorInferenceError)r   	decoratorr   r   r   decorated_with_property  s   r@  r?  c                 C   sj   |   D ].}t|tjr2| jtkr|jdkr dS | D ]}|jdkr1| jtkr1  dS qqdS )NpropertyTF)inferr   r   r  r   r   r   r   )r?  inferedr   r   r   r   r=    s   r=  r   qnamesc              	      sZ   | j r| j jng }|D ]}zt fdd| D rW  dS W q tjy*   Y qw dS )zMDetermine if the `func` node has a decorator with the qualified name `qname`.c                 3   s$    | ]}|d uo|   v V  qd S r   )qname)r   r   rD  r   r   r     s    
z!decorated_with.<locals>.<genexpr>TF)r;  r<  r   rB  r   r>  )r   rD  r;  Zdecorator_noder   rF  r   decorated_with  s   rG  i   )maxsizeis_abstract_cbc                 C   s   |du r
t ttd}i }zt|  }W n ty   i  Y S  tjy*   i  Y S w |D ]M}| D ]F}|}t	|tj
r\t|}|sM|j|v rL||j= q3t	|tjs\|j|v r\||j= t	|tjry||}|rn|||j< q3|sy|j|v ry||j= q3q-|S )a  
    Get the unimplemented abstract methods for the given *node*.

    A method can be considered abstract if the callback *is_abstract_cb*
    returns a ``True`` value. The check defaults to verifying that
    a method is decorated with abstract methods.
    The function will work only for new-style classes. For old-style
    classes, it will simply return an empty dictionary.
    For the rest of them, it will return a dictionary of abstract method
    names and their inferred objects.
    NrF  )r   rG  ABC_METHODSreversedmroNotImplementedErrorr   ZResolveErrorvaluesr   r   
safe_inferr   r   )r   rI  visitedrL  r   objrC  abstractr   r   r   unimplemented_abstract_methods  s>   

	rS  c                 C   sP   | }t jt jf}|rt|j|s|j}|rt|j|r|r&t|j|r&|jS dS )zDReturn the ExceptHandler or the TryExcept node in which the node is.N)r   r   	TryExceptr   r   )r   r   Zignoresr   r   r   find_try_except_wrapper_node+  s   rU  c                 C   sp   t | }|sdS t|tjr|jj}|jj}ntj	dd |jD }|j}t
dd |D }t|t}|p7|S )z8Check if the given node is from a fallback import block.Fc                 s   s    | ]}|j V  qd S r   )r   r   r2  r   r   r   r   C  s    
z)is_from_fallback_block.<locals>.<genexpr>c                 s   s"    | ]}t |tjtjfV  qd S r   )r   r   r   r   )r   Zimport_noder   r   r   r   H  s
    
)rU  r   r   r   r   r   handlers	itertoolschainfrom_iterabler   "_except_handlers_ignores_exceptionImportError)r   contextZ
other_bodyrW  Zhas_fallback_importsZignores_import_errorr   r   r   is_from_fallback_block9  s   

r^  rW  c                 C   s   t t|fd}tt|| S )N)r9  )r   r:  r   map)rW  	exceptionr   r   r   r   r[  P  s   r[  c                    s,   t | }t|tjr fdd|jD S dS )a]  Return the collections of handlers handling the exception in arguments.

    Args:
        node (astroid.NodeNG): A node that is potentially wrapped in a try except.
        exception (builtin.Exception or str): exception or name of the exception.

    Returns:
        list: the collection of handlers that are handling the exception or None.

    c                    s   g | ]	}t | r|qS r   )r:  rV  r`  r   r   r   f  s
    
z*get_exception_handlers.<locals>.<listcomp>N)rU  r   r   rT  rW  )r   r`  r]  r   ra  r   get_exception_handlersW  s   
rb  c                 C   s   t | }t|tjS )a  Check if the node is directly under a Try/Except statement.
    (but not under an ExceptHandler!)

    Args:
        node (astroid.Raise): the node raising the exception.

    Returns:
        bool: True if the node is inside a try/except statement, False otherwise.
    )rU  r   r   rT  )r   r]  r   r   r   is_node_inside_try_exceptl  s   
rc  c                 C   s   t | |}|s	dS t|S )zCheck if the node is in a TryExcept which handles the given exception.

    If the exception is not given, the function is going to look for bare
    excepts.
    F)rb  r   )r   r`  Zmanaging_handlersr   r   r   node_ignores_exceptionz  s   
rd  c                 C   s2   |   D ]}|j | u r|jddr dS qdS )zVreturn true if the given class node should be considered as an abstract
    class
    F)Zpass_is_abstractT)r   r   r   is_abstract)r   methodr   r   r   class_is_abstract  s   rg  r,  attrc                 C   sR   z|  |}W n tjy   Y dS w |d }t|tjr't|jjtjr'dS dS )NFr   T)r   r   ZNotFoundErrorr   r   r   r,  Const)r,  rh  
attributesfirstr   r   r   _supports_protocol_method  s   rl  c                 C   s   t jt jt jt jf}t| |S r   )r   r   SetCompDictCompGeneratorExpr   )r   Zcomprehensionsr   r   r   is_comprehension  s   
rp  c                 C   s   t | to	t | tS r   )rl  GETITEM_METHODKEYS_METHODr,  r   r   r   _supports_mapping_protocol  s
   rt  c                 C   
   t | tS r   )rl  CONTAINS_METHODrs  r   r   r   "_supports_membership_test_protocol     
rw  c                 C   s   t | tp	t | tS r   )rl  ITER_METHODrq  rs  r   r   r   _supports_iteration_protocol  s   rz  c                 C   ru  r   )rl  AITER_METHODrs  r   r   r   "_supports_async_iteration_protocol  rx  r|  c                 C   ru  r   )rl  rq  rs  r   r   r   _supports_getitem_protocol  rx  r}  c                 C   ru  r   )rl  SETITEM_METHODrs  r   r   r   _supports_setitem_protocol  rx  r  c                 C   ru  r   )rl  DELITEM_METHODrs  r   r   r   _supports_delitem_protocol  rx  r  c                 C   s<   |   }|d}|d}|dp|d}|p|p|S )NZmixinrR  r   )lowerr  r  )r   lnameZis_mixinre  Zis_baser   r   r   _is_abstract_class_name  s
   

r  c                 C   sR   | d ur't | tjr t| rdS t| dd }|d ur t|r dS | j} | d usdS )NTr   F)r   r   r  rg  r   r  r   )r   r   r   r   r   is_inside_abstract_class  s   r  protocol_callbackc                 C   s   t | tjrt| sdS |  }|d ur||rdS t | tjr2t| s&dS |  r,dS || r2dS t | tjrKt | j	tjrKt| j	rK| j	} || S dS )NTF)
r   r   r  has_known_bases	metaclassZBaseInstanceZhas_dynamic_getattr_basesZProxyZ_proxied)r,  r  metar   r   r   _supports_protocol  s.   
r  Fcheck_asyncc                 C   s   |rt }nt}t| |S r   )r|  rz  r  )r,  r  Zprotocol_checkr   r   r   is_iterable  s   
r  c                 C   ru  r   )r  rt  rs  r   r   r   
is_mapping  rx  r  c                 C   s   t | t}|p
t| S r   )r  rw  r  )r,  	supportedr   r   r   supports_membership_test
  s   
r  c                 C   s$   t | tjrt| trdS t| tS )NT)r   r   r  rl  CLASS_GETITEM_METHODr  r}  rs  r   r   r   supports_getitem  s   

r  c                 C   ru  r   )r  r  rs  r   r   r   supports_setitem  rx  r  c                 C   ru  r   )r  r  rs  r   r   r   supports_delitem  rx  r  c                 C   sj   z| j |d}t|}W n tjy   Y dS w zt| W dS  tjy*   Y dS  ty4   | Y S w )zReturn the inferred value for the given node.

    Return None if inference failed or if there is some ambiguity (more than
    one node has been inferred).
    r]  N)rB  nextr   r>  StopIteration)r   r]  Zinferitr,  r   r   r   rO    s   	rO  r  c                 C   sj   z| j W S  ty   Y nw | jD ]}t||d}t|tjr)|| u s)t||ds/d| _  dS qd| _ dS )z=Return true if all base classes of a class could be inferred.r  FT)Z_all_bases_knownr   r   rO  r   r   r  r  )r  r]  r   r  r   r   r   r  6  s$   


r  c                 C   s4   | d u pt | tjo| jd u pt | tjo| jdkS )NNone)r   r   ri  r,  r   r   r   r   r   r   is_noneJ  s
   r  c                 C   sr   t  }z"|  D ]}|tjkst|rq|| t|dkr# W dS qW n tjy0   Y dS w |r7| S dS )zReturn the inferred type for `node`

    If there is more than one possible type, or if inferred type is Uninferable or None,
    return None
    r   N)	r   rB  r   ZUninferabler  r   r   r>  pop)r   typesZvar_typer   r   r   	node_typeR  s   
r  c              	   C   s   d}t | tjs
dS | jr| jjng }|D ]9}t |tjsq|j}t |tjr,|jdkr-qz	t	|j
 }W n
 tjy@   Y qw t |tjrNt||  S qdS )z>Check if the given function node is a singledispatch function.)zfunctools.singledispatchzsingledispatch.singledispatchFregister)r   r   r   r;  r<  Callr   	Attributer   r  r   rB  r>  rG  )r   Zsingledispatch_qnamesr;  r?  r   Zfunc_defr   r   r   (is_registered_in_singledispatch_functiong  s&   r  c                 C   sn   t | ddrt| jd S t | ddrt| jd S t | ddr't| jd S t | ddr4t| jd S | jS )z
    Get the last lineno of the given node. For a simple statement this will just be node.lineno,
    but for a node that has child statements (e.g. a method) this will be the lineno of the last
    child statement recursively.
    	finalbodyForelserW  r   )r   get_node_last_linenor  r  rW  r   r   r   r   r   r   r    s   r  c                 C   s:   d}|   }|j|}|ot|d tjo|d jdkS )z;Check if the postponed evaluation of annotations is enabledannotationsr   
__future__)r   localsgetr   r   r   modname)r   r   moduler   r   r   r   is_postponed_evaluation_enabled  s   r  r   r   c              	   C   sX   t dd | |fD sdS |  D ]}ztj||rW  dS W q ty)   Y qw dS )z
    Check if first node is a subclass of second node.
    :param child: Node to check for subclass.
    :param parent: Node to check for superclass.
    :returns: True if child is derived from parent. False otherwise.
    c                 s   s    | ]	}t |tjV  qd S r   )r   r   r  )r   r   r   r   r   r     s    z!is_subclass_of.<locals>.<genexpr>FT)r  r   r   helpersZ
is_subtyper   )r   r   r   r   r   r   is_subclass_of  s   r  )NNr   )F)r   r   	functoolsr   r   rX  r  r!  sysr   typingr   r   r   r   r   r	   r
   r   r   r  r   Zastroid.exceptionsr   r   r  r   r   r   r   rm  rn  ro  r   version_infor   r0  rJ  ry  r{  ZNEXT_METHODrq  r  r~  r  rv  rr  Z_SPECIAL_METHODS_PARAMSr   ZSPECIAL_METHODS_PARAMSr   Z	PYMETHODSr   r   r   Znode_classesZNodeNGboolr   r   r  r   r   r   __dict__copyr   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:  r   r@  r=  rG  rS  rT  rU  r^  r[  rb  r   rc  rd  r  rg  rl  rp  rt  rw  rz  r|  r}  r  r  r  r  r  r  r  r  r  r  r  rO  r  r  r8  r  r  r  r  r  r   r   r   r   <module>   s  ,(>m	





0

	
"N!$
 

	
;





 
!