B
    S\&                 @   s  d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lm	Z	 ej
Ze	d
ZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZejefej_dS )a"  
Inference objects are a way to represent composite AST nodes,
which are used only as inference results, so they can't be found in the
original AST tree. For instance, inferring the following frozenset use,
leads to an inferred FrozenSet:

    Call(func=Name('frozenset'), args=Tuple(...))
    N)bases)
decorators)
exceptions)MANAGER)node_classes)scoped_nodes)utilzinterpreter.objectmodelc               @   s0   e Zd ZdZdd Zd	ddZejdd ZdS )
	FrozenSetz-class representing a FrozenSet composite nodec             C   s   dt  S )Nz%s.frozenset)BUILTINS)self r   .lib/python3.7/site-packages/astroid/objects.pypytype&   s    zFrozenSet.pytypeNc             c   s
   | V  d S )Nr   )r   contextr   r   r   _infer)   s    zFrozenSet._inferc             C   s   t j}|dd S )N	frozensetr   )r   builtins_modulegetattr)r   ast_builtinsr   r   r   _proxied,   s    zFrozenSet._proxied)N)	__name__
__module____qualname____doc__r   r   r   cachedpropertyr   r   r   r   r   r	   #   s   
r	   c               @   s~   e Zd ZdZedd Zdd ZdddZd	d
 Z	e
jdd Zdd Zdd Zedd Zdd ZdddZdddZdS )Supera  Proxy class over a super call.

    This class offers almost the same behaviour as Python's super,
    which is MRO lookups for retrieving attributes from the parents.

    The *mro_pointer* is the place in the MRO from where we should
    start looking, not counting it. *mro_type* is the object which
    provides the MRO, it can be both a type or an instance.
    *self_class* is the class where the super call is, while
    *scope* is the function where the super call is.
    c               C   s   t  S )N)objectmodelZ
SuperModelr   r   r   r   <lambda>@   s    zSuper.<lambda>c             C   s"   || _ || _d| _|| _|| _d S )NF)typemro_pointer_class_basedZ_self_class_scope)r   r   mro_typeZ
self_classZscoper   r   r   __init__C   s
    zSuper.__init__Nc             c   s
   | V  d S )Nr   )r   r   r   r   r   r   J   s    zSuper._inferc             C   s   t | jtjstjd| dt | jtjr8d| _| j}n.t| jdd}t |t	j
tjfsftjd| d|jsztjd| d| }| j|krtjd| d|| j}||d d S )	zBGet the MRO which will be used to lookup attributes in this super.zIThe first argument to super must be a subtype of type, not {mro_pointer}.)super_Tr   NzPThe second argument to super must be an instance or subtype of type, not {type}.z*Unable to call super on old-style classes.   )
isinstancer   r   ZClassDefr   
SuperErrorr   r    r   r   InstanceZnewstylemroindex)r   r"   r)   r*   r   r   r   	super_mroM   s,    

zSuper.super_mroc             C   s   t j}|dd S )Nsuperr   )r   r   r   )r   r   r   r   r   r   s   s    zSuper._proxiedc             C   s   dt  S )Nz%s.super)r
   )r   r   r   r   r   x   s    zSuper.pytypec             C   s   dS )NzSuper ofr   )r   r   r   r   display_type{   s    zSuper.display_typec             C   s   | j jS )z Get the name of the MRO pointer.)r   name)r   r   r   r   r.   ~   s    z
Super.namec             C   s   dS )Nr,   r   )r   r   r   r   qname   s    zSuper.qnamec             c   s  || j kr| j |V  dS y|  }W nz tjk
rd } ztjd| |||jd|W dd}~X Y n@ tjk
r } z tjd| |||j|j	d|W dd}~X Y nX d}x|D ]}||j
krqd}xtj|| g|| dD ]}t|tjs|V  q|jd	krt||V  q| jjd	kr0|jd
kr0|V  q| jsD|jdkrL|V  qt|ry|| |E dH  W n  tjk
r   tjV  Y nX qt||V  qW qW |stj| ||ddS )z9Retrieve the inferred values of the given attribute name.NzHLookup for {name} on {target!r} because super call {super!r} is invalid.)target	attributer   r$   zJLookup for {name} on {target!r} failed because {cls!r} has an invalid MRO.)r0   r1   r   mrosclsFT)frameclassmethodmethodstaticmethod)r0   r1   r   )special_attributeslookupr+   r   r'   ZAttributeInferenceErrorr$   ZMroErrorr2   r3   localsr   Z_infer_stmtsr&   r   FunctionDefr   ZBoundMethodr!   r    Z_is_propertyinfer_call_resultZInferenceErrorr   ZUninferable)r   r.   r   r)   excfoundr3   Zinferredr   r   r   igetattr   s\    


zSuper.igetattrc             C   s   t | j||dS )N)r   )listr?   )r   r.   r   r   r   r   r      s    zSuper.getattr)N)N)N)r   r   r   r   r   lazy_descriptorr8   r#   r   r+   r   r   r   r   r-   propertyr.   r/   r?   r   r   r   r   r   r   2   s   
&
Cr   c               @   s   e Zd ZdZejdd ZdS )ExceptionInstancezClass for instances of exceptions

    It has special treatment for some of the exceptions's attributes,
    which are transformed at runtime into certain concrete objects, such as
    the case of .args.
    c             C   s"   |   }tj|tj}| | S )N)r/   r   ZBUILTIN_EXCEPTIONSgetZExceptionInstanceModel)r   r/   instancer   r   r   r8      s    
z$ExceptionInstance.special_attributesN)r   r   r   r   r   r   r8   r   r   r   r   rC      s   rC   c               @   s   e Zd ZdZedd ZdS )DictInstancezSpecial kind of instances for dictionaries

    This instance knows the underlying object model of the dictionaries, which means
    that methods such as .values or .items can be properly inferred.
    c               C   s   t  S )N)r   Z	DictModelr   r   r   r   r      s    zDictInstance.<lambda>N)r   r   r   r   r   rA   r8   r   r   r   r   rF      s   rF   c               @   s   e Zd ZejjZejjZdS )	DictItemsN)r   r   r   r   NodeNG__str____repr__r   r   r   r   rG      s   rG   c               @   s   e Zd ZejjZejjZdS )DictKeysN)r   r   r   r   rH   rI   rJ   r   r   r   r   rK      s   rK   c               @   s   e Zd ZejjZejjZdS )
DictValuesN)r   r   r   r   rH   rI   rJ   r   r   r   r   rL      s   rL   c                   s8   e Zd ZdZd	 fdd	Zd
 fdd	Zdd Z  ZS )PartialFunctionzDA class representing partial function obtained via functools.partialNc                sD   t  ||||| t|jdd  | _|jdd  | _|j| _d S )Nr%   )r,   r#   lenZpositional_argumentsZfilled_positionalsfilled_argsZkeyword_argumentsfilled_keywords)r   Zcallr.   doclineno
col_offsetparent)	__class__r   r   r#      s    zPartialFunction.__init__c                sr   |rbdd |j jD }x0| j D ]"\}}||kr"|j j||f q"W |j jpRg }| j| |j _t j||dS )Nc             S   s   h | ]\}}|qS r   r   ).0keyword_r   r   r   	<setcomp>  s   z4PartialFunction.infer_call_result.<locals>.<setcomp>)callerr   )	ZcallcontextkeywordsrP   itemsappendargsrO   r,   r<   )r   rZ   r   Zcurrent_passed_keywordsrW   valueZcall_context_args)rU   r   r   r<     s    z!PartialFunction.infer_call_resultc             C   s   | j jS )N)rU   r   )r   r   r   r   r/     s    zPartialFunction.qname)NNNNN)NN)r   r   r   r   r#   r<   r/   __classcell__r   r   )rU   r   rM      s   rM   )r   builtinsZastroidr   r   r   r   r   r   r   r   r
   Zlazy_importr   Z_BaseContainerr	   rH   r   r(   rC   rF   ZProxyrG   rK   rL   r;   rM   ZDict	__bases__r   r   r   r   <module>   s(   
 