3
tûœ]…¦  ã            B   @   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mZ ddlmZmZ ddlmZ ddlZejZejejejej fZ!dZ"d	d
ddhZ#e$ddhƒZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.d�d*d�d+d9�d,dt�d-dy�d.�d/�d0iZ/d}d~„ e/j0ƒ D ƒZ1e2e1ƒZ3G dd€„ d€e4ƒZ5d�d‚„ Z6ej7j8e9dƒœd„d…„Z:ej7j8eej7j8 dƒœd†d‡„Z;ej7j8ee9eee<e<f  f dƒœdˆd‰„Z=ej7j8e9dƒœdŠd‹„Z>ej7j8e9dƒœdŒd�„Z?ej@jAƒ Z�d1ZBej7j8e9dƒœd�d�„ZCe<e9d‘œd’d“„ZDej7j8e<ej7j8e9d”œd•d–„ZEej7j8e9d—œd˜d™„ZFej7j8e9dƒœdšd›„ZGej7j8e9dƒœdœd�„ZHej7j8ej7j8e9džœdŸd „ZIej7j8ej7j8dƒœd¡d¢„ZJej7j8e<e9d£œd¤d¥„ZKe<e
d¦œd§d¨„ZLG d©dª„ dªe4ƒZMG d«d¬„ d¬e4ƒZNe<eee< eOee<e<f ee< f d­œd®d¯„ZPee<eee9e<f  f d°œd±d²„ZQeee<  d°œd³d´„ZRe<eeee<eee9e<f  f  eOeOf d­œdµd¶„ZSe<e9d·œd¸d¹„ZTej7j8eejU dƒœdºd»„ZVe<eee<  d·œd¼d½„ZW�d2ejXeOe<ejYd¾œd¿dÀ„ZZej7j8e9dƒœdÁdÂ„Z[ej\e9dÃœdÄdÅ„Z]ej^e9dƒœdÆdÇ„Z_dÈdÉ„ Z`ej^e9dƒœdÊdË„Zaej^e9dƒœdÌdÍ„Zbej^e9dƒœdÎdÏ„ZcejYe9dÐœdÑdÒ„Zdej^ee< e9dÓœdÔdÕ„ZeedÖd×��d3ej7j8ej^ee<ej7j8f dØœdÙdÚ„ƒZfej7j8eej\ejgf dƒœdÛdÜ„Zhej7j8e9dƒœdÝdÞ„Ziej\e9dßœdàdá„Zje4fej7j8eeej\  dƒœdâdã„Zkejle9dƒœdädå„Zme4fej7j8e9dƒœdædç„ZnejUe9dƒœdèdé„Zoej7j8e<e9dêœdëdì„Zpej7j8e9dƒœdídî„Zqej7j8e9dïœdðdñ„Zrej7j8e9dïœdòdó„Zsej7j8e9dïœdôdõ„Ztej7j8e9dïœdöd÷„Zuej7j8e9dïœdødù„Zvej7j8e9dïœdúdû„Zwej7j8e9dïœdüdý„Zxe<e9d‘œdþdÿ„Zyej7j8e9dƒœ�d �d„Zzej7j8ej^e9�dœ�d�d„Z{�d4ej7j8e9e9�dœ�d�d„Z|ej7j8e9dïœ�d	�d
„Z}ej7j8e9dïœ�d�d„Z~ej7j8e9dïœ�d�d„Zej7j8e9dïœ�d�d„Z€ej7j8e9dïœ�d�d„Z�edÖd×��d5ej7j8eej7j8 dƒœ�d�d„ƒZ‚�d6ejUe9�dœ�d�d„Zƒej7j8e9dƒœ�d�d„Z„ej7j8ee… dƒœ�d�d„Z†ej^e9dƒœ�d�d„Z‡ej7j8eOdƒœ�d�d„Zˆej7j8e9dƒœ�d �d!„Z‰ejUejUe9�d"œ�d#�d$„ZŠedÖd×�ej7j8e9dƒœ�d%�d&„ƒZ‹ej7j8e9�d'œ�d(�d)„ZŒdS (7  z7some functions that may be useful for various checkers
é    N)Ú	lru_cacheÚpartial)	ÚCallableÚDictÚIterableÚListÚMatchÚOptionalÚSetÚTupleÚUnion)Úbases)ÚhelpersÚscoped_nodes)Ú_NonDeducibleTypeHierarchyÚbuiltinszabc.abstractpropertyzabc.abstractmethodzabc.abstractclassmethodzabc.abstractstaticmethodztyping.Protocolztyping_extensions.ProtocolÚ__iter__Ú	__aiter__Ú__next__Ú__getitem__Z__class_getitem__Ú__setitem__Ú__delitem__Ú__contains__ÚkeysÚ__new__Ú__init__Ú__call__Ú__del__Ú__repr__Ú__str__Ú	__bytes__Ú__hash__Ú__bool__Ú__dir__Ú__len__Ú__length_hint__Ú__reversed__Ú__neg__Ú__pos__Ú__abs__Ú
__invert__Ú__complex__Ú__int__Ú	__float__Ú	__index__Ú	__enter__Ú
__aenter__Ú__getnewargs_ex__Ú__getnewargs__Ú__getstate__Ú
__reduce__Ú__copy__Ú__unicode__Ú__nonzero__Ú	__await__Ú	__anext__Ú
__fspath__é   Ú
__format__Ú__lt__Ú__le__Ú__eq__Ú__ne__Ú__gt__Ú__ge__Ú__getattr__Ú__getattribute__Ú__delattr__Ú
__delete__Ú__instancecheck__Ú__subclasscheck__Ú__missing__Ú__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__Ú__div__é   Ú__setattr__Ú__get__Ú__set__Ú__set_name__é   Ú__exit__Ú	__aexit__Ú	__round__c             C   s    i | ]\}}|D ]
}||“qqS © r   )Ú.0ÚparamsÚmethodsÚnamer   r   ú7/tmp/pip-build-fn42xldr/pylint/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   s4   | }x|r"t |jtjƒ r"|j}qW |o2||jjk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   s.   | j }x"|dk	r(t|tjƒr dS |j }qW 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   s<   t | tjtjfƒr2x$| jD ]}t|ƒE dH  qW n| 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 | tjƒr&d| jd| jjƒ f ffS t | tjƒr”| j}t|ƒrLd|dffS | j	|ƒd }|r”t |d j
ƒ tjtjtjfƒ r”d|d|d j ffS d	S )
zÇChecks 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)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ƒ 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   sN   d}d}x:| j tjtjfƒD ]$}t|tjƒr0d}t|tjƒrd}qW |oL| S )zAreturn true if the function does nothing but raising an exceptionFT)Únodes_of_classrŒ   ÚRaiseÚReturnrŠ   )rŽ   ZraisesZreturnsZ
child_noder   r   r„   Úis_error  s    r©   Ú__builtins__c             C   s   | o| j ƒ 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ƒ   r‘   c             C   s   | t kp| tk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Úscoper‘   c                s¢  t |tjƒr^xL|jD ]B}t |tjƒr<t‡ fdd„|jD ƒƒsRt |tjƒrˆ |jkrdS qW �n@t |t	tj
fƒr–x"|jtjƒD ]}|jˆ kr|dS q|W �nt |tjƒrâxú|jD ]2\}}|j| ƒr¾P |rªt |tjƒrª|jˆ krªdS qªW n¼t |tjtjfƒ�rj|jjˆ ƒ�rR|jj| ƒ�rNy"|jjˆ ƒ |j}t| ˆ |ƒ W n tjk
�rL   Y nX dS t|dd ƒˆ k�rždS n4t |tjƒ�ržt |jtjƒ�rž|j}|jˆ k�ržd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ÚForr¦   rš   rƒ   ÚWithÚitemsZ	parent_ofr’   ÚFunctionDefÚargsZis_argumentÚdefault_valuer‹   Úis_defined_in_scopeZ	NoDefaultr¢   r�   )r­   r®   r¯   rŽ   Zass_noder˜   Úidsr   )r®   r„   r¿   &  sH    



r¿   )r­   r‘   c             C   sº   | j }| j}x|r*t| ||ƒr"dS |j}qW | jƒ }|jƒ }|j}xr|r´|j|kr´x"|jtjƒD ]}|j |kr`dS q`W x2|jtj	tj
fƒD ]}|dd„ |jD ƒkrŠdS qŠW |jƒ }qDW dS )zÕreturn 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>j  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_beforeV  s$    

rÇ   c             C   sR   | j ƒ }t|tjtjfƒrNx2|jjD ]&}x |jtjƒD ]}|| kr6dS q6W q$W 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_argumentp  s    rË   c             C   sL   | j }x@|dk	rFt|tjƒr dS |js<t|tjtjtjfƒr>P |j }qW dS )z5return true if the name is used in function decoratorNTF)	r‹   rŠ   rŒ   Z
DecoratorsZis_statementr’   r   ZComprehensionScopeÚListComp)rŽ   r‹   r   r   r„   Úis_func_decorator}  s    

rÍ   )ÚframerŽ   r‘   c             C   sF   y
| j }W n tk
r   dS X x |D ]}||jtjƒkr&dS q&W 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*   x$| r$t | tjtjtjfƒr$| j} qW | 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_noderƒ   r‘   c             C   s2   x,| j ƒ D ] }||kr
t|| tjƒr
dS q
W 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Ö   )Úmessagesr‘   c                 s   ‡ fdd„}|S )z@decorator to store messages that are handled by a checker methodc                s
   ˆ | _ | S )N)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 j| |ƒ || _d S )N)Ú	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_stringr‘   c                sê  t ƒ }tƒ }g }d}‡ fdd„}d}�x¶|tˆ ƒk �rÜˆ | }|dk�rÒ||ƒ\}}d}|dkrÄd}	||ƒ\}}|}
x:|	dkr®|dkr�|	d7 }	n|dkr |	d8 }	||ƒ\}}qvW |d }ˆ |
|… }x|d	krÜ||ƒ\}}qÆW |d
krü|d7 }||ƒ\}}nx|tjk�r||ƒ\}}qþW |dk�rp||ƒ\}}|d
k�rP|d7 }||ƒ\}}n x|tjk�rn||ƒ\}}�qRW |dk�r†||ƒ\}}d}||k�rœt|ƒ‚|�r¶|j|ƒ |||< n|dk�rÒ|d7 }|j|ƒ |d7 }q(W ||||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%a)ÚsetÚdictrâ   ÚstringÚdigitsrÝ   Ú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Ã  sd    











rõ   )r‘   c             C   s*   y
t j| ƒS  tk
r$   tƒ ‚Y nX d S )N)Ú_stringÚformatter_field_name_splitÚ
ValueErrorrÛ   )rá   r   r   r„   Úsplit_format_field_names  s    
rù   c             c   sÂ   t jƒ }yj|j| ƒ}xZ|D ]R}tdd„ |dd… D ƒƒr:q|d }|d }|V  |rxt|ƒD ]
}|V  q^W qW W nJ tk
r¼ } z.|jd jdƒr¤dV  d	V  dS t| ƒ‚W Y dd}~X nX dS )
zy Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.
    c             s   s   | ]}|d kV  qd S )Nr   )r€   Úitemr   r   r„   r±     s    z(collect_string_fields.<locals>.<genexpr>r;   Nrv   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 ƒ }xžt| ƒD ]’}|r<t|ƒjƒ r<|jt|ƒƒ q|r¢t|ƒ\}}t|tjƒrn|jt|ƒƒ t	|ƒ}y|j
|t|ƒfƒ W qª tk
rž   tƒ ‚Y qªX q|d7 }qW ||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_string6  s"    
r  )r—   r‘   c             C   s*   | d dko(| dko(| j dƒo&| j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_protectedV  s    r  c             C   sB   | j ƒ }x4|dk	r<t|tjƒ r<|jdkr0d}q
|jj ƒ }q
W |S )z°Return 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Š   rŒ   ÚClassDefr‹   )rŽ   Úklassr   r   r„   Únode_frame_classa  s    
r  c             C   s   t jdƒ}|j| ƒ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_privater  s    
r  )Ú	call_nodeÚpositionÚkeywordr‘   c             C   sr   |dkr|dkrt dƒ‚|dk	r@y
| j| S  tk
r>   Y nX |rj| jrjx| jD ]}|j|krR|jS qRW t‚dS )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_callz  s    



r!  c             C   sN   t | dƒr| jƒ ng }x2tj| g|ƒD ] }|jdkr&|jƒ jtkr&dS q&W dS )zV
    Return true if the given class node is subclass of
    exceptions.Exception.
    rÔ   rÞ   ÚBaseExceptionTF)rÞ   r"  )ÚhasattrrÔ   Ú	itertoolsÚchainrƒ   r£   ÚEXCEPTIONS_MODULE)rŽ   rÔ   rÕ   r   r   r„   Úinherit_from_std_ex˜  s    
r'  )Úhandlerr‘   c                s>   dd„ ‰ t |tƒs|f}‡ fdd„|D ƒ}| js4dS | j|ƒ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 )N)rŠ   r  r‡   )Úerrorr   r   r„   Ústringify_error³  s    
z&error_of_type.<locals>.stringify_errorc                s   h | ]}ˆ |ƒ’qS r   r   )r€   r)  )r*  r   r„   ú	<setcomp>º  s    z error_of_type.<locals>.<setcomp>T)rŠ   ÚtupleÚtypeZcatch)r(  Ú
error_typeZexpected_errorsr   )r*  r„   Úerror_of_type§  s    
r/  c             C   sV   | j s
dS xF| j jD ]:}t|tjƒs&qyt|ƒr4dS W q tjk
rL   Y qX qW dS )z@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    
r5  c             G   sL   t | tjtjfƒsdS | jrHx*| jjD ]}t |tjƒr&|j|kr&dS q&W dS )NFT)rŠ   rŒ   ZUnboundMethodr¼   r0  r1  Ú	Attributer—   )rŽ   Zkindsr4  r   r   r„   Ú_is_property_kindÏ  s    r7  c             C   s
   t | dƒS )z,Check if the given node is a property setterÚsetter)r7  )rŽ   r   r   r„   Úis_property_setterÙ  s    r9  c             C   s
   t | dƒS )z-Check if the given node is a property deleterÚdeleter)r7  )rŽ   r   r   r„   Úis_property_deleterÞ  s    r;  c             C   s   t | ddƒS )z@Check if the given node is either a property setter or a deleterr8  r:  )r7  )rŽ   r   r   r„   Úis_property_setter_or_deleterã  s    r<  )r4  r‘   c             C   sl   xf| j ƒ D ]Z}t|tjƒr
|jƒ jtkr6|jdkr6dS x,|jƒ D ] }|jdkr@|jƒ jtkr@dS q@W q
W dS )NÚpropertyTF)ÚinferrŠ   rŒ   r  r£   rƒ   r¤   rÔ   )r4  ÚinferredrÕ   r   r   r„   r2  è  s    
r2  )rØ   Úqnamesr‘   c                sr   | j r| j jng }xZ|D ]R}t|tjƒr.|j}y"t‡ fdd„|jƒ D ƒƒrNdS W q tjk
rh   wY qX qW dS )zMDetermine if the `func` node has a decorator with the qualified name `qname`.c             3   s,   | ]$}|d k	r|j ƒ ˆ kp"|jˆ kV  qd S )N)Úqnamerƒ   )r€   rã   )r@  r   r„   r±   ÿ  s   z!decorated_with.<locals>.<genexpr>TF)	r0  r1  rŠ   rŒ   ÚCallrØ   r´   r>  r3  )rØ   r@  r0  Zdecorator_noder   )r@  r„   Údecorated_withö  s    

rC  i   )Úmaxsize)rŽ   Úis_abstract_cbr‘   c             C   s   |dkrt ttd�}i }yt| jƒ ƒ}W n( tk
r<   i S  tjk
rP   i S X x¨|D ] }xš|jƒ D ]Ž}|}t	|tj
ƒr¸t|ƒ}|sš|j|krf||j= qft	|tjƒs¸|j|kr¸||j= t	|tjƒrf||ƒ}|rÜ|||j< qf| oê|j|krf||j= qfW qXW |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.
    N)r@  )r   rC  ÚABC_METHODSÚreversedÚmroÚNotImplementedErrorrŒ   ZResolveErrorÚvaluesrŠ   rš   Ú
safe_inferrƒ   r¼   )rŽ   rE  ÚvisitedrH  rÕ   Úobjr?  Úabstractr   r   r„   Úunimplemented_abstract_methods  s8    


	rO  c             C   sH   | }t jt jf}x|r,t|j|ƒ r,|j}qW |rDt|j|ƒrD|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_nodeD  s    
rQ  c             C   sp   t | ƒ}|sdS t|tjƒr.|jj}|jj}ntjj	dd„ |jD ƒƒ}|j}t
dd„ |D ƒƒ}t|tƒ}|pn|S )z8Check if the given node is from a fallback import block.Fc             s   s   | ]}|j V  qd S )N)r³   )r€   r(  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 )N)rŠ   rŒ   rÂ   rÃ   )r€   Zimport_noder   r   r„   r±   b  s   )rQ  rŠ   rŒ   r�   r‹   r³   Úhandlersr$  r%  Úfrom_iterabler´   Ú"_except_handlers_ignores_exceptionÚImportError)rŽ   ÚcontextZ
other_bodyrR  Zhas_fallback_importsZignores_import_errorr   r   r„   Úis_from_fallback_blockR  s    


rW  )rR  r‘   c             C   s   t t|fd�}tt|| ƒƒS )N)r.  )r   r/  r´   Úmap)rR  Ú	exceptionrØ   r   r   r„   rT  i  s    rT  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 (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/  )r€   r(  )rY  r   r„   rÁ   €  s    z*get_exception_handlers.<locals>.<listcomp>)rQ  rŠ   rŒ   rP  rR  )rŽ   rY  rV  r   )rY  r„   Úget_exception_handlersp  s    rZ  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.
    )rQ  rŠ   rŒ   rP  )rŽ   rV  r   r   r„   Úis_node_inside_try_except…  s    
r[  c             C   s   t | |ƒ}|sdS t|ƒS )z£Check 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)rZ  r´   )rŽ   rY  Zmanaging_handlersr   r   r„   Únode_ignores_exception“  s    
r\  c             C   s4   x.| j ƒ D ]"}|jjƒ | kr
|jdd�r
dS q
W 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
    r_  )r   Úattrr‘   c             C   sR   y| j |ƒ}W n tjk
r$   dS X |d }t|tjƒrNt|jjtjƒrNdS dS )NFr   T)r¢   rŒ   ZNotFoundErrorrŠ   rš   r‹   r   ÚConst)r   r`  Ú
attributesÚfirstr   r   r„   Ú_supports_protocol_method¬  s    rd  c             C   s   t jt jt jt jf}t| |ƒS )N)rŒ   rÌ   ÚSetCompÚDictCompÚGeneratorExprŠ   )rŽ   Zcomprehensionsr   r   r„   Úis_comprehension¹  s
    rh  )r   r‘   c             C   s   t | tƒot | tƒS )N)rd  ÚGETITEM_METHODÚKEYS_METHOD)r   r   r   r„   Ú_supports_mapping_protocolÃ  s    rk  c             C   s
   t | tƒS )N)rd  ÚCONTAINS_METHOD)r   r   r   r„   Ú"_supports_membership_test_protocolÉ  s    rm  c             C   s   t | tƒpt | tƒS )N)rd  ÚITER_METHODri  )r   r   r   r„   Ú_supports_iteration_protocolÍ  s    ro  c             C   s
   t | tƒS )N)rd  ÚAITER_METHOD)r   r   r   r„   Ú"_supports_async_iteration_protocolÓ  s    rq  c             C   s
   t | tƒS )N)rd  ri  )r   r   r   r„   Ú_supports_getitem_protocol×  s    rr  c             C   s
   t | tƒS )N)rd  ÚSETITEM_METHOD)r   r   r   r„   Ú_supports_setitem_protocolÛ  s    rt  c             C   s
   t | tƒS )N)rd  ÚDELITEM_METHOD)r   r   r   r„   Ú_supports_delitem_protocolß  s    rv  c             C   s<   | j ƒ }|jdƒ}|jdƒ}|jdƒp.|jdƒ}|p:|p:|S )NZmixinrN  rÐ   )Úlowerr  r  )rƒ   ÚlnameZis_mixinr]  Úis_baser   r   r„   Ú_is_abstract_class_nameã  s
    

rz  c             C   sP   xJ| d k	rJt | tjƒrBt| ƒr"dS t| dd ƒ}|d k	rBt|ƒrBdS | j} qW dS )NTrƒ   F)rŠ   rŒ   r  r_  r¢   rz  r‹   )rŽ   rƒ   r   r   r„   Úis_inside_abstract_classë  s    

r{  )r   Úprotocol_callbackr‘   c             C   sš   t | tjƒr4t| ƒsdS | jƒ }|d k	r4||ƒr4dS t | tjƒrdt| ƒsLdS | jƒ rXdS || ƒrddS t | tjƒr–t | j	tjƒr–t| j	ƒr–| 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)r   Úcheck_asyncr‘   c             C   s   |r
t }nt}t| |ƒS )N)rq  ro  r�  )r   r‚  Zprotocol_checkr   r   r„   Úis_iterable  s    rƒ  c             C   s
   t | tƒS )N)r�  rk  )r   r   r   r„   Ú
is_mapping  s    r„  c             C   s   t | tƒ}|pt| ƒS )N)r�  rm  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  rd  ÚCLASS_GETITEM_METHODr�  rr  )r   r   r   r„   Úsupports_getitem&  s    
rˆ  c             C   s
   t | tƒS )N)r�  rt  )r   r   r   r„   Úsupports_setitem-  s    r‰  c             C   s
   t | tƒS )N)r�  rv  )r   r   r   r„   Úsupports_delitem1  s    rŠ  c             C   sj   y| j |d�}t|ƒ}W n tjk
r.   dS X yt|ƒ dS  tjk
rR   dS  tk
rd   |S X dS )z¡Return 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).
    )rV  N)r>  ÚnextrŒ   r3  ÚStopIteration)rŽ   rV  Zinferitr   r   r   r„   rK  5  s    	rK  )r  r‘   c             C   sp   y| j S  tk
r   Y nX xH| jD ]>}t||d�}t|tjƒ sX|| ksXt||d� r$d| _ dS q$W d| _ dS )z=Return true if all base classes of a class could be inferred.)rV  FT)Z_all_bases_knownrÏ   r   rK  rŠ   rŒ   r  r}  )r  rV  rÐ   r  r   r   r„   r}  L  s    r}  c             C   s4   | d kp2t | tjƒr| jd kp2t | tjƒo2| jdkS )NÚNone)rŠ   rŒ   ra  r   rÉ   rƒ   )rŽ   r   r   r„   Úis_none_  s    rŽ  c             C   sr   t ƒ }yDx>| jƒ D ]2}|tjkst|ƒr*q|j|ƒ t|ƒdkrdS qW W n tjk
r`   dS X |rn|jƒ S dS )z’Return 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ê   r>  rŒ   ZUninferablerŽ  rî   râ   r3  Úpop)rŽ   ÚtypesZvar_typer   r   r„   Ú	node_typeg  s    
r‘  c             C   s¨   d}t | tjƒsdS | jr"| jjng }x||D ]t}t |tjƒs>q,|j}t |tjƒ s,|jdkr^q,yt	|j
jƒ ƒ}W n tjk
rˆ   w,Y nX t |tjƒr,t||ƒS q,W dS )z>Check if the given function node is a singledispatch function.úfunctools.singledispatchúsingledispatch.singledispatchFÚregister)r’  r“  )rŠ   rŒ   r¼   r0  r1  rB  rØ   r6  r—   r‹  r˜   r>  r3  rC  )rŽ   Zsingledispatch_qnamesr0  r4  rØ   Z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ƒr4t| jd ƒS t | ddƒrNt| jd	 ƒS t | ddƒrht| 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.
    Ú	finalbodyFr;   ÚorelserR  r³   éÿÿÿÿr˜  r˜  r˜  )r¢   Úget_node_last_linenor–  r—  rR  r³   rÆ   )rŽ   r   r   r„   r™  �  s    r™  c             C   s:   d}| j ƒ }|jj|ƒ}|o8t|d tjƒo8|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‹   r‘   c             C   s\   t dd„ | |fD ƒƒsdS x<| jƒ D ]0}ytj||ƒr:dS W q$ tk
rR   w$Y q$X 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 )N)rŠ   rŒ   r  )r€   rŽ   r   r   r„   r±   Ç  s    z!is_subclass_of.<locals>.<genexpr>FT)rÿ   rÔ   r   Z
is_subtyper   )r–   r‹   rÕ   r   r   r„   Úis_subclass_ofÀ  s    r¡  c             C   s   t | tjƒot| dgƒS )zµCheck 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.
    ztyping.overload)rŠ   rŒ   r¼   rC  )rŽ   r   r   r„   Úis_overload_stubÓ  s    r¢  )Úclsr‘   c             C   s&   t | tjƒsdS tdd„ | jƒ D ƒƒS )z§Check 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   | ]}|j ƒ tkV  qd S )N)rA  ÚTYPING_PROTOCOLS)r€   r‹   r   r   r„   r±   ê  s    z$is_protocol_class.<locals>.<genexpr>)rŠ   rŒ   r  r´   rÔ   )r£  r   r   r„   Úis_protocol_classß  s    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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r   r9   r:   )=r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r   rI   r   r   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   )rw   rx   ry   r   rz   )r|   r}   )r   r;   )r~   )rª   )NN)N)F)N)N)�rÜ   r   r$  r	  r  rì   Ú	functoolsr   r   Útypingr   r   r   r   r   r	   r
   r   r   rŒ   r   r  r   r   Zastroid.exceptionsr   rö   r‡   r¤   rÌ   re  rf  rg  r¸   r&  rF  Ú	frozensetr¤  rn  rp  ZNEXT_METHODri  r‡  rs  ru  rl  rj  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  rB  rÉ   r!  r'  r�   r/  r¼   r5  r7  r9  r;  r<  r2  rC  rO  rP  rQ  rW  rT  rZ  r§   r[  r\  r_  rd  rh  rk  rm  ro  rq  rr  rt  rv  rz  r{  r�  rƒ  r„  r†  rˆ  r‰  rŠ  rK  r}  rŽ  r-  r‘  r•  r™  r   r¡  r¢  r¥  r   r   r   r„   Ú<module>   sÒ  ,                                                                                                 	
"
,

*I""0	
:



 
!