3
tûœ]±  ã               @   s’   d dl Z d dlmZ d dlZd dlZdd„ Zdd„ ZejG dd„ dƒƒZ	G d	d
„ d
ƒZ
G dd„ de
ƒZG dd„ de
ƒZdd„ Zdd„ Zdd„ ZdS )é    N)Úislicec             C   s   G dd„ dt jƒ}|| ƒS )Nc               @   s   e Zd Zddd„ZdS )z(lazy_descriptor.<locals>.DescriptorProxyNc             S   s   | j j| |ƒS )N)Ú	__class__Ú__get__)ÚselfÚinstanceÚowner© r   ú//tmp/pip-build-fn42xldr/astroid/astroid/util.pyr      s    z0lazy_descriptor.<locals>.DescriptorProxy.__get__)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r	   ÚDescriptorProxy   s   r   )Úlazy_object_proxyÚProxy)Úobjr   r   r   r	   Úlazy_descriptor   s    r   c                s   t j‡ fdd„ƒS )Nc                  s   t jdˆ  dƒS )NÚ.Zastroid)Ú	importlibÚimport_moduler   )Úmodule_namer   r	   Ú<lambda>   s    zlazy_import.<locals>.<lambda>)r   r   )r   r   )r   r	   Úlazy_import   s    r   c               @   s@   e Zd ZdZdd„ ZeZdd„ Zdd„ Zdd	„ ZeZ	d
d„ Z
dS )ÚUninferablezASpecial inference object, which is returned when inference fails.c             C   s   dS )Nr   r   )r   r   r   r	   Ú__repr__"   s    zUninferable.__repr__c             C   sH   |dkrt dƒ‚|jdƒr0|jdƒr0tj| |ƒS |dkrDtj| |ƒS | S )NÚnextz next method should not be calledÚ__Úaccept)ÚAttributeErrorÚ
startswithÚendswithÚobjectÚ__getattribute__)r   Únamer   r   r	   r!   '   s    zUninferable.__getattribute__c             O   s   | S )Nr   )r   ÚargsÚkwargsr   r   r	   Ú__call__0   s    zUninferable.__call__c             C   s   dS )NFr   )r   r   r   r	   Ú__bool__3   s    zUninferable.__bool__c             C   s   t |dƒ}|| ƒS )NZvisit_uninferable)Úgetattr)r   ÚvisitorÚfuncr   r   r	   r   8   s    
zUninferable.acceptN)r
   r   r   Ú__doc__r   Ú__str__r!   r%   r&   Ú__nonzero__r   r   r   r   r	   r      s   	r   c               @   s   e Zd ZdZdS )ÚBadOperationMessagez¿Object which describes a TypeError occurred somewhere in the inference chain

    This is not an exception, but a container object which holds the types and
    the error which occurred.
    N)r
   r   r   r*   r   r   r   r	   r-   =   s   r-   c               @   s4   e Zd ZdZdd„ Zedd„ ƒZdd„ Zdd	„ Zd
S )ÚBadUnaryOperationMessagez8Object which describes operational failures on UnaryOps.c             C   s   || _ || _|| _d S )N)ÚoperandÚopÚerror)r   r/   r0   r1   r   r   r	   Ú__init__H   s    z!BadUnaryOperationMessage.__init__c             C   s   t dƒ}|jS )NÚhelpers)r   Úobject_type)r   r3   r   r   r	   Ú_object_type_helperM   s    z,BadUnaryOperationMessage._object_type_helperc             C   s   | j |ƒ}|tkrd S |S )N)r5   r   )r   r   Zobjtyper   r   r	   Ú_object_typeR   s    
z%BadUnaryOperationMessage._object_typec             C   sN   t | jdƒr| jj}n&| j| jƒ}t |dƒr4|j}n|jƒ }d}|j| j|ƒS )Nr"   z!bad operand type for unary {}: {})Úhasattrr/   r"   r6   Ú	as_stringÚformatr0   )r   Zoperand_typer4   Úmsgr   r   r	   r+   Z   s    

z BadUnaryOperationMessage.__str__N)	r
   r   r   r*   r2   Úpropertyr5   r6   r+   r   r   r   r	   r.   E   s
   r.   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚBadBinaryOperationMessagez.Object which describes type errors for BinOps.c             C   s   || _ || _|| _d S )N)Ú	left_typeÚ
right_typer0   )r   r=   r0   r>   r   r   r	   r2   l   s    z"BadBinaryOperationMessage.__init__c             C   s   d}|j | j| jj| jjƒS )Nz1unsupported operand type(s) for {}: {!r} and {!r})r9   r0   r=   r"   r>   )r   r:   r   r   r	   r+   q   s    z!BadBinaryOperationMessage.__str__N)r
   r   r   r*   r2   r+   r   r   r   r	   r<   i   s   r<   c             C   s@   | j }|j}||kpt||ƒ}tjd| jj|jf tdd� |S )NzF%r is deprecated and slated for removal in astroid 2.0, use %r insteadé   )Ú
stacklevel)Ú__wrapped__r   Ú
issubclassÚwarningsÚwarnr
   ÚPendingDeprecationWarning)ÚclsÚotherÚwrappedZ	other_clsZis_instance_ofr   r   r	   Ú_instancecheckv   s    rI   c                s,   t | tjftjd tdœƒ}|‡ fdd„ƒS )z7Get a Proxy from the given name to the given node type.r   )r   Ú__instancecheck__c                  s   ˆ S )Nr   r   )Ú	node_typer   r	   r   �   s    zproxy_alias.<locals>.<lambda>)Útyper   r   r    Ú__dict__rI   )Z
alias_namerK   Úproxyr   )rK   r	   Úproxy_aliasƒ   s    
rO   c             c   s0   t | |ƒE dH  t| dƒ}|dk	r,tV  dS dS )a§  Limit inference amount.

    Limit inference amount to help with performance issues with
    exponentially exploding possible results.

    :param iterator: Inference generator to limit
    :type iterator: Iterator(NodeNG)

    :param size: Maximum mount of nodes yielded plus an
        Uninferable at the end if limit reached
    :type size: int

    :yields: A possibly modified generator
    :rtype param: Iterable
    NF)r   r   r   )ÚiteratorÚsizeZhas_morer   r   r	   Úlimit_inference�   s
    
rR   )rC   Ú	itertoolsr   r   r   r   r   r    Ú__new__r   r-   r.   r<   rI   rO   rR   r   r   r   r	   Ú<module>	   s   $