B
    A!p\>              	   @   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#sd	Z$nd
Z$dd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dddZ/dd  e/0 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<f f d%d*d+Z=ej7j8e9d%d,d-Z>ej7j8e9d%d.d/Z?ej@A Zd0ZBej7j8e9d%d1d2ZCe<e9d3d4d5ZDej7j8e<ej7j8e9d6d7d8ZEej7j8e9d9d:d;ZFej7j8e9d%d<d=ZGej7j8e9d%d>d?ZHej7j8ej7j8e9d@dAdBZIej7j8ej7j8d%dCdDZJej7j8e<e9dEdFdGZKe<edHdIdJZLG dKdL dLe4ZMG dMdN dNe4ZNe<eee< eOee<e<f ee< f dOdPdQZPee<eee9e<f  f dRdSdTZQeee<  dRdUdVZRe<eeee<eee9e<f  f  eOeOf dOdWdXZSe<e9dYdZd[ZTej7j8eej7j8 d%d\d]ZUe<eee<  dYd^d_ZVdejWeOe<ejXd`dadbZYej7j8e9d%dcddZZej[e9dedfdgZ\ej]e9d%dhdiZ^ejXe9djdkdlZ_ej]ee< e9dmdndoZ`edpdqdej7j8ej]ee<ej7j8f drdsdtZaej7j8eej[ejbf d%dudvZcej7j8e9d%dwdxZdej[e9dydzd{Zee4fej7j8eej[ d%d|d}Zfejge9d%d~dZhe4fej7j8e9d%ddZiejje9d%ddZkej7j8e<e9dddZlej7j8e9d%ddZmej7j8e9dddZnej7j8e9dddZoej7j8e9dddZpej7j8e9dddZqej7j8e9dddZrej7j8e9dddZsej7j8e9dddZte<e9d3ddZuej7j8e9d%ddZvej7j8ej]e9dddZwdej7j8e9e9dddZxej7j8e9dddZyej7j8e9dddZzej7j8e9dddZ{ej7j8e9dddZ|ej7j8e9dddZ}edpdqdej7j8eej7j8 d%ddZ~dejje9dddZej7j8e9d%ddZej7j8ee d%ddZej]e9d%ddZej7j8eOd%ddZej7j8e9d%ddZejjejje9d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builtinszabc.abstractpropertyzabc.abstractmethodzabc.abstractclassmethodz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+   r-   r.   r/   	__index__	__enter__
__aenter____getnewargs_ex____getnewargs____getstate__
__reduce____copy__Z__unicode__Z__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   ry   c             C   s    i | ]\}}|D ]
}||qqS  r{   ).0Zparamsmethodsnamer{   r{   4lib/python3.7/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   s2   | }x|r t |jtjs |j}qW |o0||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   sF   t | tjtjfr<x.| jD ]}xt|D ]
}|V  q(W qW n| V  dS )z9Recursively returns all atoms in nested lists and tuples.N)r   r   r   r   Z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r| j}t|rLd|dffS | 	|d }|rt |d 
 tjtjtjfsd|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   ry   r   zouter scope (line %s))FN)r   r   Z
AssignAttrattrnameexprZ	as_string
AssignNamer~   
is_builtinlookupZassign_typeAssignZ	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&   x |   D ]}t|tjr
dS q
W dS )zAreturn true if the function does nothing but raising an exceptionTF)Zget_childrenr   r   Raise)r   Z
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~   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rx"|tjD ]}|j kr|dS q|W nt |tjrx|jD ]2\}}|| rP |rt |tjr|j krdS qW nt |tjtjfrj|j rR|j| rNy"|j  |j}t|  | W n tjk
rL   Y nX dS t|dd  krdS n4t |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>1  s   z&is_defined_in_scope.<locals>.<genexpr>Tr~   F)r   r   ZIfbodyr   anyZtargetsZNonlocalnamesCOMP_NODE_TYPESZFornodes_of_classr   r~   ZWithitemsZ	parent_ofr   FunctionDefargsZis_argumentZdefault_valuer   is_defined_in_scopeZ	NoDefaultr   r   )r   r   r   r   Zass_noder   Zidsr{   )r   r   r   '  sH    



r   )r   r   c             C   s   | j }| j}x|r*t| ||r"dS |j}qW |  }| }|j}xr|r|j|krx"|tjD ]}|j |kr`dS q`W x2|tj	tj
fD ]}|dd |jD krdS qW | }qDW 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 )ry   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   Z_nodestmtlinenoZassign_nodeZimp_noder{   r{   r   is_defined_beforeW  s$    

r   c             C   sR   |   }t|tjtjfrNx2|jjD ]&}x |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   Zdefault_nodeZdefault_name_noder{   r{   r   is_default_argumentq  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 ]}||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,|   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 | | || _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rd}	||\}}|}
x:|	dkr|dkr|	d7 }	n|dkr|	d8 }	||\}}qvW |d } |
| }x|d	kr||\}}qW |d
kr|d7 }||\}}nx|tjkr||\}}qW |dkrp||\}}|d
krP|d7 }||\}}n x|tjkrn||\}}qRW |dkr||\}}trd}nd}||krt||r|| |||< n|dkr|d7 }|| |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 )Nry   )lenr   )i)r   r{   r   	next_char  s    z&parse_format_string.<locals>.next_char%N(ry   )z#0- +*.ZhlLzdiouxXeEfFgGcrs%azdiouxXeEfFgGcrs%)	setdictr   stringZdigitsPY3Kr   addappend)r   r   Z	key_typesZ	pos_typesZnum_argsr   r   charkeyZdepthZ	key_startZkey_endflagsr{   )r   r   parse_format_string  sh    











r   )r   c             C   s*   y
t | S  tk
r$   t Y nX d S )N)_stringZformatter_field_name_split
ValueErrorr   )r   r{   r{   r   split_format_field_names  s    
r   c          
   c   s   t  }yj|| }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 drdV  d	V  dS t| W dd}~X Y 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>ry   Nrz   r   zcannot switch from manual 1)	r   Z	Formatterparseallcollect_string_fieldsr   r   
startswithr   )r   Z	formatterZparseiteratorresultr~   nestedZfieldexcr{   r{   r   r     s$    

r   c          	   C   s   g }d}t  }xt| D ]}|r<t| r<|t| q|rt|\}}t|tjrn|t| t	|}y|
|t|f W q tk
r   t Y qX 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   ry   )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   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   s@   |   }x2|dk	r:t|tjs:|jdkr.d}q
|j  }q
W |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   Zregexr{   r{   r   is_attr_privatev  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_call~  s    



r	  c             C   sD   | j dk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 )N)inherit_from_std_ex)r|   r   r{   r{   r   r     s    z&inherit_from_std_ex.<locals>.<genexpr>)Zrecurs)r~   r   EXCEPTIONS_MODULEhasattrr   r   )r   r{   r{   r   r    s    

r  )handlerr   c                s>   dd  t |ts|f} fdd|D }| js4d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 )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 )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  r   c             C   sl   xf|   D ]Z}t|tjr
| jtkr6|jdkr6dS x,| D ] }|jdkr@| jtkr@dS q@W q
W dS )NpropertyTF)inferr   r   r   r   r~   r   r   )r  inferedr   r{   r{   r   r    s    
r  )r   qnamesr   c          	      s`   | j r| j jng }xH|D ]@}y"t fdd| D r<dS W q tjk
rV   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	o|   kV  qd S )N)Zqname)r|   r   )r  r{   r   r     s    z!decorated_with.<locals>.<genexpr>TF)r  r  r   r  r   r  )r   r  r  Zdecorator_noder{   )r  r   decorated_with  s    
r   i   )maxsize)r   is_abstract_cbr   c             C   s   |dkrt ttd}i }yt|  }W n( tk
r<   i S  tjk
rP   i S X x|D ]}x| D ]}|}t	|tj
rt|}|s|j|krf||j= qft	|tjs|j|kr||j= t	|tjrf||}|r|||j< qf|sf|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   r   ABC_METHODSreversedmroNotImplementedErrorr   ZResolveErrorvaluesr   r   
safe_inferr~   r   )r   r"  Zvisitedr%  r   objr  abstractr{   r{   r   unimplemented_abstract_methods  s8    


	r+  c             C   sF   | }t jt jf}x|r*t|j|s*|j}qW |rBt|j|rB|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    
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}|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   D  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   I  s   )r-  r   r   r   r   r   handlers	itertoolschainfrom_iterabler   "_except_handlers_ignores_exceptionImportError)r   contextZ
other_bodyr.  Zhas_fallback_importsZignores_import_errorr{   r{   r   is_from_fallback_block9  s    


r5  )r.  r   c             C   s   t t|fd}tt|| S )N)r  )r   r  r   map)r.  	exceptionr   r{   r{   r   r2  P  s    r2  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  )r|   r  )r7  r{   r   r   g  s    z*get_exception_handlers.<locals>.<listcomp>N)r-  r   r   r,  r.  )r   r7  r4  r{   )r7  r   get_exception_handlersW  s    r8  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.
    )r-  r   r   r,  )r   r4  r{   r{   r   is_node_inside_try_exceptl  s    
r9  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)r8  r   )r   r7  Zmanaging_handlersr{   r{   r   node_ignores_exceptionz  s    
r:  c             C   s4   x.|   D ]"}|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|  |}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>  Z
attributesfirstr{   r{   r   _supports_protocol_method  s    rA  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
    rE  )r  r   c             C   s   t | tot | tS )N)rA  GETITEM_METHODKEYS_METHOD)r  r{   r{   r   _supports_mapping_protocol  s    rH  c             C   s
   t | tS )N)rA  CONTAINS_METHOD)r  r{   r{   r   "_supports_membership_test_protocol  s    rJ  c             C   s   t | tpt | tS )N)rA  ITER_METHODrF  )r  r{   r{   r   _supports_iteration_protocol  s    rL  c             C   s
   t | tS )N)rA  AITER_METHOD)r  r{   r{   r   "_supports_async_iteration_protocol  s    rN  c             C   s
   t | tS )N)rA  rF  )r  r{   r{   r   _supports_getitem_protocol  s    rO  c             C   s
   t | tS )N)rA  SETITEM_METHOD)r  r{   r{   r   _supports_setitem_protocol  s    rQ  c             C   s
   t | tS )N)rA  DELITEM_METHOD)r  r{   r{   r   _supports_delitem_protocol  s    rS  c             C   s<   |   }|d}|d}|dp.|d}|p:|p:|S )NZmixinr*  r   )lowerr   r   )r~   ZlnameZis_mixinr;  Zis_baser{   r{   r   _is_abstract_class_name  s
    

rU  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   rU  r   )r   r~   r{   r{   r   is_inside_abstract_class  s    

rV  )r  protocol_callbackr   c             C   s   t | tjr4t| sdS |  }|d k	r4||r4dS t | tjrdt| sLdS |  rXdS || rddS t | tjrt | j	tjrt| j	r| j	} || S dS )NTF)
r   r   r   has_known_bases	metaclassZBaseInstanceZhas_dynamic_getattr_basesZProxyZ_proxied)r  rW  metar{   r{   r   _supports_protocol  s(    
r\  F)r  check_asyncr   c             C   s   |r
t }nt}t| |S )N)rN  rL  r\  )r  r]  Zprotocol_checkr{   r{   r   is_iterable  s    r^  c             C   s
   t | tS )N)r\  rH  )r  r{   r{   r   
is_mapping  s    r_  c             C   s   t | t}|pt| S )N)r\  rJ  r^  )r  Z	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   rA  CLASS_GETITEM_METHODr\  rO  )r  r{   r{   r   supports_getitem  s    
rb  c             C   s
   t | tS )N)r\  rQ  )r  r{   r{   r   supports_setitem  s    rc  c             C   s
   t | tS )N)r\  rS  )r  r{   r{   r   supports_delitem  s    rd  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 )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).
    )r4  N)r  nextr   r  StopIteration)r   r4  Zinferitr  r{   r{   r   r(    s    	r(  )r   r   c             C   sl   y| j S  tk
r   Y nX xD| jD ]:}t||d}t|tjrT|| ksTt||ds$d| _ dS q$W d| _ dS )z=Return true if all base classes of a class could be inferred.)r4  FT)Z_all_bases_knownr   r   r(  r   r   r   rX  )r   r4  r   r   r{   r{   r   rX  6  s    rX  c             C   s4   | d kp2t | tjr| jd kp2t | tjo2| jdkS )NNone)r   r   r?  r  r   r~   )r   r{   r{   r   is_noneJ  s    rh  c             C   sr   t  }yDx>|  D ]2}|tjkst|r*q|| t|dkrdS qW W n tjk
r`   dS X |rn| 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
    ry   N)	r   r  r   ZUninferablerh  r   r   r  pop)r   typesZvar_typer{   r{   r   	node_typeR  s    
rk  c          	   C   s   d}t | tjsdS | jr"| jjng }xz|D ]r}t |tjs>q,|j}t |tjr,|jdkr\q,yt	|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.)zfunctools.singledispatchzsingledispatch.singledispatchFregister)r   r   r   r  r  Callr   Z	Attributer   re  r   r  r  r   )r   Zsingledispatch_qnamesr  r  r   Zfunc_defr{   r{   r   (is_registered_in_singledispatch_functiong  s"    
rn  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.
    	finalbodyForelser.  r   )r   get_node_last_linenoro  rq  r.  r   r   )r   r{   r{   r   rr    s    rr  c             C   s:   d}|   }|j|}|o8t|d tjo8|d jdkS )z;Check if the postponed evaluation of annotations is enabledZannotationsr   Z
__future__)r   localsgetr   r   r   modname)r   r~   moduler   r{   r{   r   is_postponed_evaluation_enabled  s    rw  )r   r   r   c          	   C   s^   t dd | |fD sdS x>|  D ]2}ytj||r<dS W q$ tk
rT   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helpersZ
is_subtyper   )r   r   r   r{   r{   r   is_subclass_of  s    rx  )NN)N)F)N)N)r   r   	functoolsr   r   r/  r   r   sysr   typingr   r   r   r   r   r	   r
   r   r   r   r   Zastroid.exceptionsr   r   rZ  r   r   r   r   rB  rC  rD  r   version_infor   r  r#  rK  rM  ZNEXT_METHODrF  ra  rP  rR  rI  rG  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  rm  r   r	  r  r   r  r   r  r  r   r+  r,  r-  r5  r2  r8  r   r9  r:  r   r=  rA  rE  rH  rJ  rL  rN  rO  rQ  rS  rU  rV  r\  r^  r_  r`  rb  rc  rd  r(  rX  rh  r  rk  rn  rr  rw  rx  r{   r{   r{   r   <module>   s  ,(=	
,

*L""0	
:



!