Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/helpers.cpython-37.opt-1.pyc

B

��\w#�@s�dZddlZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZej
Zdd�Zd
d�Zd'dd�Zd(dd�Zd)dd�Zd*dd�Zd+dd�Zd,dd�Zd-dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd.d%d&�ZdS)/z
Various helper utilities.
�N)�bases)�context)�
exceptions)�manager)�nodes)�raw_building)�scoped_nodes)�utilcCst�|�}||_|S)N)rZbuild_class�parent)�cls_name�builtins�proxy�r�@/opt/alt/python37/lib/python3.7/site-packages/astroid/helpers.py�_build_proxy_classs
rcCsRt|tj�r&|��jtkr d}qHd}n"t|tj�r8d}nt|tj�rHd}t	||�S)NZbuiltin_function_or_method�function�method)
�
isinstancer�Lambda�root�name�BUILTINSr�BoundMethod�
UnboundMethodr)rrrrrr�_function_type"srccs�t��}|j}|pt��}x�|j|d�D]~}t|tj�rd|j	rR|�
�}|rR|Vq(|�d�dVq(t|tjt
jf�r�t||�Vq(t|tj�r�td|�Vq(|jVq(WdS)N)r�typer�module)rZAstroidManagerZbuiltins_module�
contextmod�InferenceContext�inferrr�ClassDef�newstyle�	metaclass�getattrrrrrZModulerZ_proxied)�noderZastroid_managerr�inferredr"rrr�_object_type/s r&cCsNytt||��}Wntjk
r*tjSXt|�dks<|sBtjSt|�dS)aUObtain the type of the given node

    This is used to implement the ``type`` builtin, which means that it's
    used for inferring type calls, as well as used in a couple of other places
    in the inference.
    The node will be inferred first, so this function can support all
    sorts of objects, as long as they support inference.
    �r)�setr&r�InferenceErrorr	�Uninferable�len�list)r$r�typesrrr�object_typeDs
r.cCs|t|ttf�s|f}n|}|tjkr*tjSdd�|D�}x>|D]6}|tjkrVt�d��x|��D]}||kr`dSq`Wq>WdS)NcSs"g|]}t|tj�s|ntj�qSr)rrZInstancer	r*)�.0�itemrrr�
<listcomp>bsz,_object_type_is_subclass.<locals>.<listcomp>z&arg 2 must be a type or tuple of typesTF)r�tupler,r	r*r�AstroidTypeError�mro)�obj_type�class_or_seqrZ	class_seq�klassZobj_subclassrrr�_object_type_is_subclassWs



r8cCs(t||�}|tjkrtjSt|||d�S)z�Check if a node 'isinstance' any node in class_or_seq

    :param node: A given node
    :param class_or_seq: Union[nodes.NodeNG, Sequence[nodes.NodeNG]]
    :rtype: bool

    :raises AstroidTypeError: if the given ``classes_or_seq`` are not types
    )r)r.r	r*r8)r$r6rr5rrr�object_isinstancers	

r9cCs*t|tj�stdj|d���t|||d�S)arCheck if a type is a subclass of any node in class_or_seq

    :param node: A given node
    :param class_or_seq: Union[Nodes.NodeNG, Sequence[nodes.NodeNG]]
    :rtype: bool

    :raises AstroidTypeError: if the given ``classes_or_seq`` are not types
    :raises AstroidError: if the type of the given node cannot be inferred
        or its type's mro doesn't work
    z"{node} needs to be a ClassDef node)r$)r)rrr �	TypeError�formatr8)r$r6rrrr�object_issubclass�sr<cCsjy|j|d�}t|�}Wntjk
r.dSXyt|�dStjk
rRdStk
rd|SXdS)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).
    )rN)r�nextrr)�
StopIteration)r$rZinferit�valuerrr�
safe_infer�sr@cCsly|jStk
rYnXxD|jD]:}t||d�}t|tj�rT||ksTt||d�s$d|_dSq$Wd|_dS)z=Return true if all base classes of a class could be inferred.)rFT)Z_all_bases_known�AttributeErrorrr@rrr �has_known_bases)r7r�base�resultrrrrB�srBcCsbttt||f��stj�t|j|jg�s,dSy||��dd�kStjk
r\tj�YnXdS)NF���)�all�maprBrZ_NonDeducibleTypeHierarchyr!r4ZMroError)�type1�type2rrr�_type_check�srJcCs
t||�S)z(Check if *type1* is a subtype of *typ2*.)rJ)rHrIrrr�
is_subtype�srKcCs
t||�S)z+Check if *type2* is a supertype of *type1*.)rJ)rHrIrrr�is_supertype�srLcCs�t��}tj|gd�|_y^xX|jd|d�D]F}t|tj�s<q*x2|j||d�D] }t|t	j
�rLt|jt�rL|SqLWq*WWnt
jk
r�YnXdS)z�Get the value as an index for the given instance.

    If an instance provides an __index__ method, then it can
    be used in some scenarios where an integer is expected,
    for instance when multiplying or subscripting a list.
    )�args�	__index__)rN)rrZCallContextZcallcontext�igetattrrrr�infer_call_resultr�Constr?�intrr))r$rr%rDrrr�class_instance_as_index�srSc	Cs(ddlm}t||d�}|dks*|tjkr6tj|d��t|tj	�r\t|j
ttf�r\t
|j
�St|tjtjtj|f�r~t
|j�St|tj�r�t
|j�Sy"t||d�}t|jd|d��}Wn*tjk
r�t�d�|�����YnXt|�||��}t|tj	��r|��dk�r|j
St�d	�|���dS)
a�Infer length of given node object

    :param Union[nodes.ClassDef, nodes.Instance] node:
    :param node: Node to infer length of

    :raises AstroidTypeError: If an invalid node is returned
        from __len__ method or no __len__ method exists
    :raises InferenceError: If the given node cannot be inferred
        or if multiple nodes are inferred
    :rtype int: Integer length of node
    r)�	FrozenSet)rN)r$�__len__z object of type '{}' has no len()zbuiltins.intz/'{}' object cannot be interpreted as an integer)Zastroid.objectsrTr@r	r*rr)rrrQr?�bytes�strr+ZList�SetZTupleZeltsZDict�itemsr.r=rOZAttributeInferenceErrorr3r;ZpytyperP)r$rrTZ
inferred_nodeZ	node_typeZlen_callZ
result_of_lenrrr�
object_len�s.


rZ)N)N)N)N)N)N)N)N)�__doc__rZbuiltins_modZastroidrrrrrrrrr	�__name__rrrr&r.r8r9r<r@rBrJrKrLrSrZrrrr�<module>s0