o
    g                     @   s|	  d 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 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ZddlmZmZ ddlmZ ejejejejfZdZdd	hZ h d
Z!e"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dZ-dd e-. D Z/e0e/Z1e"dZ2G d d! d!e3Z4G d"d# d#e3Z5d$ej6d%e7fd&d'Z8d$ej6d%eej6 fd(d)Z9d$ej6d%e7fd*d+Z:d$ej;d%e7fd,d-Z<ej=> Zd.Z?d$ej6d%e7fd/d0Z@d1eAd%e7fd2d3ZBd4ej6d5eAd6ej6d%e7fd7d8ZCd4ejDd%e7fd9d:ZE	dd$ej6d6eej6 d%e7fd;d<ZFd$ej6d%e7fd=d>ZGd?ejHd$ej6d%e7fd@dAZId$ej6d%e7fdBdCZJd$ej6d%ej6fdDdEZKdFejHd1eAd%e7fdGdHZLdIeAd%e
fdJdKZMG dLdM dMe3ZNG dNdO dOe3ZOdPeAd%eeeA ePeeAeAf eeA f fdQdRZQd%eeAeee7eAf  f fdSdTZRd%eeeA  fdUdVZSdPeAd%eeeeAeee7eAf  f  ePePf fdWdXZTdYeAd%e7fdZd[ZUd$ej6d%eejH fd\d]ZVdYeAd%eeeA  fd^d_ZW	dd`ejXdaePdbeAd%ejDfdcddZYd$ej6d%e7fdedfZZdgej[d%e7fdhdiZ\d$ej;d%e7fdjdkZ]dldm Z^d$ej;d%e7fdndoZ_d$ej;d%e7fdpdqZ`d$ej;d%e7fdrdsZadtejDd%e7fdudvZbdweej;ejcejdf dxeeA d%e7fdydzZeed{d|	dd$ejHd}ej;d%eeAej6f fd~dZfd$ej6d%eeej[ejgf  fddZhd$ej6d%eeej[ejgf  fddZid$ej6d%e7fddZjdej[d%e7fddZke3fd$ej6d%eeej[  fddZld$ejmd%e7fddZne3fd$ej6d%e7fddZod$ejHd%e7fddZpdej6deAd%e7fddZqd$ej6d%e7fddZrdej6d%e7fddZsdej6d%e7fddZtdej6d%e7fddZudej6d%e7fddZvdej6d%e7fddZwdej6d%e7fddZxdej6d%e7fddZyd1eAd%e7fddZzd$ej6d%e7fddZ{dej6dej;d%e7fddZ|ddej6de7d%e7fddZ}dej6d%e7fddZ~dej6d%e7fddZdej6d$ej6d%e7fddZdej6dej6d%e7fddZdej6dej6d%e7fddZdd Zed{d|dd$ej6d%eej6 fddZedd|	dd$ej6ded%eej6 fddZddejHd%e7fddńZd$ej6d%e7fddǄZd$ej6d%eej6 fddɄZd$ej;d%e7fdd˄Zd$ej6d%ePfdd̈́Zd$ej6d%e7fddτZdejHd$ej6d%e7fddфZd$ej6d%e7fddӄZdejHdejHd%e7fddׄZed{d|d$ej6d%e7fddلZdej6d%e7fdd܄Zd$ej6d1eAd%e7fddބZ	dd$ej6deej6 d%e7fddZd$ejHd%e7fddZd$eejHejf deAd%e7fddZd$ejdeAd%e7fddZd$eejejf d%eeA fddZd$ejd%ejfddZdeejejf deAd%eAfddZd$ej6d%e7fddZd$ej6d5eAd%e7fddZdS )z7some functions that may be useful for various checkers
    N)	lru_cachepartial)	CallableDictIterableListMatchOptionalSetTupleUnion)TooManyLevelsErrornodes)InferenceContextbuiltinsabc_py_abc>   abc.abstractmethodabc.abstractpropertyabc.abstractclassmethodabc.abstractstaticmethod>   	.Protocoltyping.Protocoltyping_extensions.Protocol__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__	__index__	__trunc__	__floor____ceil__	__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____rfloordiv____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____cmp__
__matmul____rmatmul____imatmul____div__)__setattr____get____set__r   __set_name__)__exit__	__aexit__)	__round__)__pow__)Nr            )r   r   )r   r   c                 C   s    i | ]\}}|D ]}||qqS  r   ).0paramsmethodsnamer   r   S/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/checkers/utils.py
<dictcomp>   s    r   )&zbuiltins.tuplezbuiltins.listzbuiltins.dictzbuiltins.setzbuiltins.frozensetzbuiltins.typezcollections.dequezcollections.defaultdictzcollections.OrderedDictzcollections.Counterzcollections.ChainMapz_collections_abc.Awaitablez_collections_abc.Coroutinez_collections_abc.AsyncIterablez_collections_abc.AsyncIteratorz_collections_abc.AsyncGeneratorz_collections_abc.Iterablez_collections_abc.Iteratorz_collections_abc.Generatorz_collections_abc.Reversiblez_collections_abc.Containerz_collections_abc.Collectionz_collections_abc.Callablez_collections_abc.Setz_collections_abc.MutableSetz_collections_abc.Mappingz_collections_abc.MutableMappingz_collections_abc.Sequencez _collections_abc.MutableSequencez_collections_abc.ByteStringz_collections_abc.MappingViewz_collections_abc.KeysViewz_collections_abc.ItemsViewz_collections_abc.ValuesViewz!contextlib.AbstractContextManagerz&contextlib.AbstractAsyncContextManagerz
re.Patternzre.Matchc                   @      e Zd ZdS )NoSuchArgumentErrorN__name__
__module____qualname__r   r   r   r   r         r   c                   @   r   )InferredTypeErrorNr   r   r   r   r   r     r   r   node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)parent
isinstancer   Lambdar   r   r   r   r   is_inside_lambda  s   r   c                 c   s<    t | tjtjfr| jD ]	}t|E dH  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   childr   r   r   r     s   

r   c                 C   s&   t | dddkr|  jdkrdS dS )zCreturn True if the node is referencing the "super" builtin functionr   Nsuperr   TF)getattrrootr   r   r   r   r   is_super)  s   r   c                 C   s    t | jdkot| jd tjS )z?Return true if the given function node only raises an exceptionr   r   )lenbodyr   r   Raiser   r   r   r   is_error0  s    r   )__builtins__c                 C   s   | o|   jdkS )zHReturns True if the given node is an object from the __builtin__ module.r   )r   r   r   r   r   r   is_builtin_object9  s   r   r   c                 C   s   | t v p| tv S )zHreturn true if <name> could be considered as a builtin defined by python)r   SPECIAL_BUILTINS)r   r   r   r   
is_builtin>  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   
AssignNamer   )r   targetr   r   r   	<genexpr>L  
    
z&is_defined_in_scope.<locals>.<genexpr>Tr   F)r   r   Ifr   AssignanytargetsNonlocalnamesCOMP_NODE_TYPESFornodes_of_classr   r   Withitems	parent_ofr   FunctionDefargsis_argumentdefault_valuer   is_defined_in_scopeastroid	NoDefaultr   ExceptHandler)r   r   r   r   ass_nodeexpridsr   r   r   r   C  sf   






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 )a  Check if the given variable node is defined before

    Verify that 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>  s    z%is_defined_before.<locals>.<listcomp>F)r   r   r   	statementprevious_sibling
fromlinenor   r   r   
ImportFromImportr   )r   r   _nodestmtlinenoassign_nodeimp_noder   r   r   is_defined_befores  s,   
r   c                 C   sR   |s|   }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_nodedefault_name_noder   r   r   is_default_argument  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   
Decoratorsis_statementr   ComprehensionScopeListCompr   r   r   r   is_func_decorator  s    r   framec                 C   s6   t | tjsdS | j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   r   ClassDefbasesr   r   )r   r   baser   r   r   is_ancestor_name  s   
r   c                 C   s   t | jtjo| jj| u S )z?return True if node is the function being called in a Call node)r   r   r   Callfuncr   r   r   r   is_being_called  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 )zGreturn 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   )checks_msgsr   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  }i }g }d} fdd}d}|t k r | }|dkr||\}}d}|dkr^d}	||\}}|}
|	dkrT|dkrB|	d7 }	n|dkrJ|	d8 }	||\}}|	dks9|d } |
| }|d	v rl||\}}|d	v sb|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||\}}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   )r   r   )ir  r   r   	next_char  s   z&parse_format_string.<locals>.next_char%N(r   )z#0- +*.hlLzdiouxXeEfFgGcrs%a)setr   stringdigitsr   addappend)r  r"   	key_types	pos_typesnum_argsr  r  charkeydepth	key_startkey_endflagsr   r  r   parse_format_string  sn   







4r  c              
   C   s.   zt | W S  ty } zt |d }~ww r   )_stringformatter_field_name_split
ValueErrorr   )r  er   r   r   split_format_field_names5  s   r  c              
   c   s    t  }z/|| }|D ]$}tdd |dd D rq|d }|d }|V  |r1t|E dH  qW dS  tyZ } z|jd drQdV  d	V  W Y d}~dS t| |d}~ww )
zxGiven 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   E      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  	formatterparseiteratorresultr   nestedexcr   r   r   r'  <  s,   
	
r'  c                 C   s   g }d}t  }t| D ]G}|rt| r|t| q|rNt|\}}t|tjr2|t| z|	|t
|f W q tyM } zt |d}~w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   Nr   )r  r'  strisdigitr  r  r   numbersNumberr  listr  r   r   )r  keyword_argumentsimplicit_pos_args_cntexplicit_pos_argsr   keynamefielditeratorr  r   r   r   parse_format_method_string\  s$   

r8  attrnamec                 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)r9  r   r   r   is_attr_protectedy  s
   r=  c                 C   sh   |   }tjtjtjf}|r2t||r2t|tjs2|jdu r dS |j  }|r2t||r2t|tjr|S )zReturn the class that is wrapping the given node

    The function returns a class for a method node (or a staticmethod or a
    classmethod), otherwise it returns `None`.
    N)	r   r   NodeNGr   UnboundMethodBaseInstancer   r   r   )r   klassnodes_to_checkr   r   r   node_frame_class  s*   




rC  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)r9  regexr   r   r   is_attr_private  s   

rH  	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 nodes.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: nodes.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   )rI  rJ  rK  rN  r   r   r   get_argument_from_call  s   



rP  c                 C   sL   t | dr	|  ng }t| g|D ]}|jdv r#| jtkr# dS qdS )zV
    Return true if the given class node is subclass of
    exceptions.Exception.
    r   )r   BaseExceptionTF)hasattrr   	itertoolschainr   r   EXCEPTIONS_MODULE)r   r   r   r   r   r   inherit_from_std_ex  s   
rV  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   rX  rY  r   r   	<setcomp>  s    z error_of_type.<locals>.<setcomp>F)r   tupletypecatch)rW  
error_typeexpected_errorsr   rZ  r   error_of_type  s   

ra  c              	   C   sD   | j sdS | j jD ]}z
t|rW  dS W q	 tjy   Y q	w dS )z?Detect if the given function node is decorated with a property.FT)
decoratorsr   _is_property_decoratorr   InferenceError)r   	decoratorr   r   r   decorated_with_property  s   rf  c                 G   sJ   t | tjtjfsdS | jr#| jjD ]}t |tjr"|j|v r" dS qdS )NFT)r   r   r?  r   r   rb  	Attributer9  )r   kindsre  r   r   r   _is_property_kind  s   ri  c                 C   
   t | dS )z,Check if the given node is a property settersetterri  r   r   r   r   is_property_setter     
rm  c                 C   rj  )z-Check if the given node is a property deleterdeleterrl  r   r   r   r   is_property_deleter  rn  rp  c                 C   s   t | ddS )z@Check if the given node is either a property setter or a deleterrk  ro  rl  r   r   r   r   is_property_setter_or_deleter  s   rq  re  c                 C   s   |   D ]e}t|tjr-| dv r dS | D ]}|jdkr+| jdkr+  dS qqt|tjrit	|
 }t|dkrit|d jtjtjfrit|d j}|rit|tjjrit|jtjrit|j  S qdS )N)zbuiltins.propertyzfunctools.cached_propertyTpropertyr   r   r   F)inferr   r   r   qnamer   r   r   r   r2   _get_return_nodes_skip_functionsr   rO  r   rg  
safe_inferr   objectsPropertyfunctionrf  )re  inferredr   returnsr   r   r   rc    s4   rc  r   qnamesc              	      sl   | j r| j jng }|D ](}t|tjr|j}zt fdd| D r(W  dS W q tjy3   Y qw dS )zMDetermine if the `func` node has a decorator with the qualified name `qname`.c                 3   s8    | ]}|d ur|t jkr|j v p|  v V  qd S r   )r   Uninferabler   rt  )r   r  r|  r   r   r   7  s    z!decorated_with.<locals>.<genexpr>TF)	rb  r   r   r   r   r   rs  r   rd  )r   r|  rb  decorator_noder   r~  r   decorated_with,  s   r  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.
    Nr~  )r   r  ABC_METHODSreversedmroNotImplementedErrorr   ResolveErrorvaluesr   r   r   rv  r   r   )r   r  visitedr  r   objrz  abstractr   r   r   unimplemented_abstract_methodsB  s>   

	r  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   currentignoresr   r   r   find_try_except_wrapper_node~  s   r  c                 C   sD   | }|j dur |j }t|tjjrdS t|tjr|S |j dusdS )zJReturn the ExceptHandler in which the node is, without going out of scope.N)r   r   r   scoped_nodesLocalsDictNodeNGr   r   )r   r  r   r   r   !find_except_wrapper_node_in_scope  s   


r  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   rW  r   r   r   r     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   import_noder   r   r   r     s
    
)r  r   r   r   r   r   handlersrS  rT  from_iterabler   "_except_handlers_ignores_exceptionImportError)r   context
other_bodyr  has_fallback_importsignores_import_errorr   r   r   is_from_fallback_block  s   

r  r  c                    s$   t t|fd t fdd| D S )N)r_  c                 3   s    | ]} |V  qd S r   r   r  r   r   r   r     r!  z5_except_handlers_ignores_exception.<locals>.<genexpr>)r   ra  r   )r  	exceptionr   r   r   r    s   r  c                    s,   t | }t|tjr fdd|jD S g S )a[  Return the collections of handlers handling the exception in arguments.

    Args:
        node (nodes.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   )ra  r  r  r   r   r     s
    
z*get_exception_handlers.<locals>.<listcomp>)r  r   r   r  r  )r   r  r  r   r  r   get_exception_handlers  s   
r  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 (nodes.Raise): the node raising the exception.

    Returns:
        bool: True if the node is inside a try/except statement, False otherwise.
    )r  r   r   r  r   r  r   r   r   is_node_inside_try_except  s   
r  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)r  r   )r   r  managing_handlersr   r   r   node_ignores_exception  s   
r  c                 C   s   |   }|dur|jdkr| jtv rdS |  D ]}|jdkr+| jtv r+ dS q|  D ]}|j | u rB|jddrB dS q0dS )zVreturn true if the given class node should be considered as an abstract
    class
    NABCMetaTABCF)pass_is_abstract)	declared_metaclassr   r   ABC_MODULESr   r   r   r   is_abstract)r   metar   methodr   r   r   class_is_abstract  s   r  rO  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   NotFoundErrorr   r   r   r   rO  Const)rO  r  
attributesfirstr   r   r   _supports_protocol_method  s   r  c                 C   s   t jt jt jt jf}t| |S r   )r   r   SetCompDictCompGeneratorExpr   )r   comprehensionsr   r   r   is_comprehension  s   
r  c                 C   s   t | to	t | tS r   )r  GETITEM_METHODKEYS_METHODrO  r   r   r   _supports_mapping_protocol  s
   r  c                 C   
   t | tS r   )r  CONTAINS_METHODr  r   r   r   "_supports_membership_test_protocol     
r  c                 C   s   t | tp	t | tS r   )r  ITER_METHODr  r  r   r   r   _supports_iteration_protocol"  s   r  c                 C   r  r   )r  AITER_METHODr  r   r   r   "_supports_async_iteration_protocol(  r  r  c                 C   r  r   )r  r  r  r   r   r   _supports_getitem_protocol,  r  r  c                 C   r  r   )r  SETITEM_METHODr  r   r   r   _supports_setitem_protocol0  r  r  c                 C   r  r   )r  DELITEM_METHODr  r   r   r   _supports_delitem_protocol4  r  r  c                 C   s<   |   }|d}|d}|dp|d}|p|p|S )Nmixinr  r   )lowerr<  r(  )r   lnameis_mixinr  is_baser   r   r   _is_abstract_class_name8  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   r  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j	rLt | j
tjrLt| j
rL| j
} || S dS )NTF)r   r   r   has_known_bases	metaclassr   r@  has_dynamic_getattrr   Proxy_proxied)rO  r  r  r   r   r   _supports_protocolL  s.   r  Fcheck_asyncc                 C   s   |rt }nt}t| |S r   )r  r  r  )rO  r  protocol_checkr   r   r   is_iterablej  s   
r  c                 C   r  r   )r  r  r  r   r   r   
is_mappingr  r  r  c                 C   s   t | t}|p
t| S r   )r  r  r  )rO  	supportedr   r   r   supports_membership_testv  s   
r  c                 C   s2   t | tjrt| trdS t| |rdS t| tS )NT)r   r   r   r  CLASS_GETITEM_METHOD?is_class_subscriptable_pep585_with_postponed_evaluation_enabledr  r  rO  r   r   r   r   supports_getitem{  s   


r  r:  c                 C   r  r   )r  r  rO  r:  r   r   r   supports_setitem  r  r  c                 C   r  r   )r  r  r  r   r   r   supports_delitem  r  r  c                 C   s   t | dd }t|r| S d S )Npytype)r   callable)r   r  r   r   r   _get_python_type_of_node  s   r  c                 C   s   t  }z| j|d}t|}W n tjy   Y dS w |tjur'|t| z|D ]}t|}||vr8 W dS q*W n tjyE   Y dS  tyO   | Y S w t	|dkrX|S dS )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 of different types).
    r  Nr   )
r  rs  nextr   rd  r}  r  r  StopIterationr   )r   r  inferred_types	infer_genrO  rz  inferred_typer   r   r   rv    s,   
rv  i   r  c                 C   s,   z	t | j|dW S  tjy   g  Y S w )Nr  )r2  rs  r   rd  r  r   r   r   	infer_all  s
   r  rA  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)_all_bases_knownAttributeErrorr   rv  r   r   r   r  )rA  r  r   r+  r   r   r   r    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   r  rO  r   r   r   r   r   r   is_none  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  rs  r   r}  r  r  r   rd  pop)r   typesvar_typer   r   r   	node_type  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   rb  r   r   rg  r9  r  r   rs  r   rd  r  )r   singledispatch_qnamesrb  re  r   func_defr   r   r   (is_registered_in_singledispatch_function  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orelser  r   )r   get_node_last_linenor  r  r  r   r   r   r   r   r   r     s   r   c                 C   s   |   }d|jv S )z;Check if the postponed evaluation of annotations is enabledannotations)r   future_imports)r   moduler   r   r   is_postponed_evaluation_enabled"  s   
r  c                 C   s   t |o|  tv ot|S )zWCheck if class is subscriptable with PEP 585 and
    postponed evaluation enabled.
    )r  rt  SUBSCRIPTABLE_CLASSES_PEP585"is_node_in_type_annotation_contextr  r   r   r   r  (  s
   
r  c                 C   s   | | j }}	 t|tjr|j|ks7t|tjr,|g |j|j|j|j	|j
R v s7t|tjr9|j|kr9dS ||j }}t|tjrGdS q)zCheck if node is in type annotation context.

    Check for 'AnnAssign', function 'Arguments',
    or part of function return type anntation.
    TF)r   r   r   	AnnAssign
annotation	Argumentsr  posonlyargs_annotationskwonlyargs_annotationsvarargannotationkwargannotationr   r{  Module)r   current_nodeparent_noder   r   r   r  5  s8   




	r  r   r   c              	   C   s\   t dd | |fD sdS |  D ]}ztj||rW  dS W q tjj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   Z      z!is_subclass_of.<locals>.<genexpr>FT)r&  r   r   helpers
is_subtype
exceptions_NonDeducibleTypeHierarchy)r   r   r   r   r   r   is_subclass_ofS  s   r  c                 C   s"   t | dd}t|ot| ddgS )zCheck if a node if is a function stub decorated with typing.overload.

    :param node: Node to check.
    :returns: True if node is an overload function stub. False otherwise.
    rb  Nztyping.overloadoverload)r   boolr  )r   rb  r   r   r   is_overload_stubf  s   r  clsc                 C   s&   t | tjsdS tdd |  D S )zCheck if the given node represents a protocol class

    :param cls: The node to check
    :returns: True if the node is a typing protocol class, false otherwise.
    Fc                 s   s    | ]	}|  tv V  qd S r   )rt  TYPING_PROTOCOLS)r   r   r   r   r   r   |  r  z$is_protocol_class.<locals>.<genexpr>)r   r   r   r   r   )r  r   r   r   is_protocol_classq  s   r  c                 C   s&   t | tjot | jtjo| jj|kS )z5Checks if node is a function call with the given name)r   r   r   r   r   r   r  r   r   r   is_call_of_name  s
   
r  c                 C   sd   |p| j }t|tjtjtjtjfr| |ju p|j| S t|tj	r(| |j
v S t|do1|| S )z=Returns true if the given node is being tested for truthinessr  )r   r   r   Whiler   IfExpAsserttestr   Comprehensionifsr  r   r   r   r   is_test_condition  s   

r$  c                 C   s:   | j dkrdS | jD ]}t|tjr|j dkr dS q
dS )zTest if ClassDef node is Type.r]  TF)r   r   r   r   r   )r   r   r   r   r   is_classdef_type  s   

r%  	attr_namec                 C   sn   | j |dgd }|rt|tjrt|jtjrdS | jD ]}t|}|r4t|tj	r4t
||r4 dS qdS )zQTest if attribute is typed annotation in current node
    or any base nodes.
    Nr   TF)localsgetr   r   r   r   r  r   rv  r   is_attribute_typed_annotation)r   r&  	attributer   rz  r   r   r   r)    s&   


r)  typing_namec                 C   s`   t | jtjs	dS | jj}t |tjr|j}t |tjr!|j|ks,t |tj	r.|j
|kr.dS dS )zTest if AssignName node has `typing_name` annotation.

    Especially useful to check for `typing._SpecialForm` instances
    like: `Union`, `Optional`, `Literal`, `ClassVar`, `Final`.
    FT)r   r   r   r  r  	SubscriptrO  r   r   rg  r9  )r   r+  r  r   r   r   is_assign_name_annotated_with  s   



r-  c                 C   s   t | jtjr.t | jjtjr.| jjjdkr.t| jj}t |tj	s$dS | j
 dd S t | jtjtjfrJt| j}t |tjsEdS | j
 S dS )zGet the name of the dictionary which keys are being iterated over on
    a ``nodes.For`` or ``nodes.Comprehension`` node.

    If the iterating object is not either the keys method of a dictionary
    or a dictionary itself, this returns None.
    r"   Nz.keysr   )r   iterr   r   r   rg  r9  rv  r   BoundMethod	as_string
rpartitionr   r   r   rz  r   r   r   get_iterating_dictionary_name  s   

r3  c                 C   s"   t | j}t|tjstd|S )a   
    Returns the value 'subscript.slice' of a Subscript node.

    :param node: Subscript Node to extract value from
    :returns: Const Node containing subscript value
    :raises InferredTypeError: if the subscript node cannot be inferred as a Const
    z3Subscript.slice cannot be inferred as a nodes.Const)rv  slicer   r   r  r   r2  r   r   r   get_subscript_const_value  s   
r5  
importnodemodnamec                 C   sT   t | tjr(| jr(|  }t |tjr(z	|j|| jdW S  ty'   | Y S w |S )a  Get a prepared module name from the given import node

    In the case of relative imports, this will return the
    absolute qualified module name, which might be useful
    for debugging. Otherwise, the initial module name
    is returned unchanged.

    :param importnode: node representing import statement.
    :param modname: module name from import statement.
    :returns: absolute qualified module name of the module
        used in import.
    )level)r   r   r   r8  r   r  relative_to_absolute_namer   )r6  r7  r   r   r   r   get_import_name  s   r:  c                 C   s"   t | jtjo| j p| j S )zlReturn True if node is part for guarded if block.
    I.e. `sys.version_info` or `typing.TYPE_CHECKING`
    )r   r   r   r   is_sys_guardis_typing_guardr   r   r   r   is_node_in_guarded_import_block  s   r=  c                    s*   t  fdd  tjtjfD S )zWCheck if the given variable name is reassigned in the same scope after the current nodec                 3   s&    | ]}|j ko|j jkV  qd S r   )r   r   )r   ar   r   r   r   r     r   z.is_reassigned_after_current.<locals>.<genexpr>)r   r   r   r   r   r   r?  r   r?  r   is_reassigned_after_current  s   r@  r   )NN)F)r   r   rS  r0  rD  r  	functoolsr   r   typingr   r   r   r   r   r	   r
   r   r   r  r   astroid.objectsr   r   astroid.contextr   r   r  r  r  r   rU  r  r  	frozensetr  r  r  NEXT_METHODr  r  r  r  r  r  _SPECIAL_METHODS_PARAMSr   SPECIAL_METHODS_PARAMSr  	PYMETHODSr  r   r   r   r>  r  r   r   r   r   r   __dict__copyr   r   r.  r   r   r   r   r   r   r   r   r   r   r   r   r   r   intr  r  r'  r8  r=  rC  rH  r   rP  rV  r   ra  rf  ri  rm  rp  rq  rc  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  r  r  r  r  rv  r  r  r  r  r  r   r  r  r  r  r  r  r  r$  r%  Instancer)  r   r-  r   r"  r3  r,  r  r5  r   r   r:  r=  r@  r   r   r   r   <module>   s  6,%@m,



0

	
"K $
	


;





		!






	