3
tûœ]—&  ã               @   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	j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   ú2/tmp/pip-build-fn42xldr/astroid/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}|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j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 jƒ 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ƒ }| j|krštjd| d�‚|j| 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   Ú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}|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 j|ƒV  dS y| jƒ }W nz tjk
rd } ztjd| |||jd�|‚W Y dd}~X n@ tjk
r¢ } z"tjd| |||j|j	d�|‚W Y dd}~X nX d}� xþ|D ]ö}||j
krÀq°d}xàtj|| g|| d�D ]Æ}t|tjƒsô|V  qÜ|jd	k�rtj||ƒV  qÜ| jjd	k�r2|jd
k�r2|V  qÜ| j�sF|jdk�rN|V  qÜtj|ƒ�r”y|j| |ƒE dH  W n  tjk
�r�   tjV  Y nX qÜtj||ƒV  qÜW q°W |�sÀt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.)r1   r2   r   ÚmrosÚclsFT)ÚframeÚclassmethodÚmethodÚstaticmethod)r1   r2   r   )Úspecial_attributesÚlookupr,   r   r(   ZAttributeInferenceErrorr$   ZMroErrorr3   r4   Úlocalsr   Z_infer_stmtsr&   r   ÚFunctionDefr   ZBoundMethodr!   r    Z_is_propertyÚinfer_call_resultZInferenceErrorr   ZUninferable)r   r/   r   r*   ÚexcÚfoundr4   Úinferredr   r   r   Úigetattr†   s\    

zSuper.igetattrc             C   s   t | j||d�ƒS )N)r   )ÚlistrA   )r   r/   r   r   r   r   r   É   s    zSuper.getattr)N)N)N)r   r   r   r   r   Úlazy_descriptorr9   r#   r   r,   r   r   r   r   r.   Úpropertyr/   r0   rA   r   r   r   r   r   r   2   s   
&
Cr   c               @   s   e Zd ZdZejdd„ ƒZdS )ÚExceptionInstancezÐClass 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"   | j ƒ }tjj|tjƒ}|ƒ | ƒS )N)r0   r   ZBUILTIN_EXCEPTIONSÚgetZExceptionInstanceModel)r   r0   Úinstancer   r   r   r9   Õ   s    
z$ExceptionInstance.special_attributesN)r   r   r   r   r   r   r9   r   r   r   r   rE   Í   s   rE   c               @   s   e Zd ZdZejdd„ ƒZdS )ÚDictInstancezÊSpecial 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 jƒ S )N)r   Z	DictModelr   r   r   r   r   æ   s    zDictInstance.<lambda>N)r   r   r   r   r   rC   r9   r   r   r   r   rH   Þ   s   rH   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   rI   ì   s   rI   c               @   s   e Zd ZejjZejjZdS )ÚDictKeysN)r   r   r   r   rJ   rK   rL   r   r   r   r   rM   ñ   s   rM   c               @   s   e Zd ZejjZejjZdS )Ú
DictValuesN)r   r   r   r   rJ   rK   rL   r   r   r   r   rN   ö   s   rN   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 ƒ j|||||ƒ 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   Úcallr/   ÚdocÚlinenoÚ
col_offsetÚparent)Ú	__class__r   r   r#   þ   s    zPartialFunction.__init__c                sr   |rbdd„ |j jD ƒ}x0| jjƒ D ]"\}}||kr"|j 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ÚkeywordsrR   ÚitemsÚappendÚargsrQ   r-   r=   )r   r]   r   Zcurrent_passed_keywordsrZ   ÚvalueZcall_context_args)rX   r   r   r=     s    z!PartialFunction.infer_call_resultc             C   s   | j jS )N)rX   r   )r   r   r   r   r0     s    zPartialFunction.qname)NNNNN)NN)r   r   r   r   r#   r=   r0   Ú__classcell__r   r   )rX   r   rO   û   s   rO   )r   ÚbuiltinsZastroidr   r   r   r   r   r   r   r   r
   Zlazy_importr   Z_BaseContainerr	   rJ   r   r)   rE   rH   ZProxyrI   rM   rN   r<   rO   ÚDictÚ	__bases__r   r   r   r   Ú<module>   s(   
 