B
    S\                 @   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 | |S )N)	__class____get__)selfinstanceowner r   +lib/python3.7/site-packages/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  fddS )Nc                  s   t 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|dr0|dr0t| |S |dkrDt| |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   Zvisitorfuncr   r   r	   r   8   s    
zUninferable.acceptN)r
   r   r   __doc__r   __str__r!   r%   r&   Z__nonzero__r   r   r   r   r	   r      s   	r   c               @   s   e Zd ZdZdS )BadOperationMessagezObject 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-   r.   r/   r   r   r	   __init__H   s    z!BadUnaryOperationMessage.__init__c             C   s   t d}|jS )Nhelpers)r   object_type)r   r1   r   r   r	   _object_type_helperM   s    z,BadUnaryOperationMessage._object_type_helperc             C   s   |  |}|tkrd S |S )N)r3   r   )r   r   Zobjtyper   r   r	   _object_typeR   s    
z%BadUnaryOperationMessage._object_typec             C   sN   t | jdr| jj}n&| | j}t |dr4|j}n| }d}|| j|S )Nr"   z!bad operand type for unary {}: {})hasattrr-   r"   r4   Z	as_stringformatr.   )r   Zoperand_typer2   msgr   r   r	   r*   Z   s    

z BadUnaryOperationMessage.__str__N)	r
   r   r   r)   r0   propertyr3   r4   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_typer.   )r   r:   r.   r;   r   r   r	   r0   l   s    z"BadBinaryOperationMessage.__init__c             C   s   d}| | j| jj| jjS )Nz1unsupported operand type(s) for {}: {!r} and {!r})r6   r.   r:   r"   r;   )r   r7   r   r   r	   r*   q   s    z!BadBinaryOperationMessage.__str__N)r
   r   r   r)   r0   r*   r   r   r   r	   r9   i   s   r9   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    rF   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__rF   )Z
alias_namerH   proxyr   )rH   r	   proxy_alias   s    
rL   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
    
rO   )r@   	itertoolsr   r   r   r   r   r    __new__r   r+   r,   r9   rF   rL   rO   r   r   r   r	   <module>	   s   $