B
    KhhS                 @   s  d Z ddlmZ ddlZddlmZ dd Zdd Zd2d	d
ZG dd deZ	e	de
fi Zee_de_ edfddZedfddZedfddZedfddZefddZefddZG dd dZdd Zdd  ZG d!d" d"ZG d#d$ d$Ze ZG d%d& d&eZe ZG d'd( d(ed)ZG d*d+ d+ed)ZG d,d- d-ed)ZG d.d/ d/ed)Z x&eeee fD ]Z!d0j"e!jd1e!_ qdW [!dS )3zDefines experimental extensions to the standard "typing" module that are
supported by the mypy typechecker.

Example usage:
    from mypy_extensions import TypedDict
    )AnyN)_type_checkc          	   C   s>   y t djd dkrtdW n ttfk
r8   Y nX dS )N   __name__)abc	functoolstypingz4TypedDict does not support instance and class checksF)sys	_getframe	f_globals	TypeErrorAttributeError
ValueError)clsother r   </tmp/pip-install-vv81h98y/mypy-extensions/mypy_extensions.py_check_fails   s    r   c             O   s
   t ||S )N)dict)r   argskwargsr   r   r   	_dict_new   s    r   c          	   K   sv   | dd}|d kr|}n|r&tdt||d}ytdjdd|d< W n ttfk
rh   Y nX t	|d	|S )
NtotalTz@TypedDict takes either a dict or keyword arguments, but not both)__annotations__	__total__r   r   __main__
__module__r   )
popr   r   r	   r
   r   getr   r   _TypedDictMeta)r   Z	_typename_fieldsr   r   nsr   r   r   _typeddict_new   s    r"   c                   s&   e Zd Zd fdd	Ze ZZ  ZS )r   Tc                s   |dkrt nt|d< tt| | |tf|}|di }d  fdd| D }x |D ]}||j	di  qXW ||_
t|ds||_|S )N	TypedDict__new__r   z?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typec                s   i | ]\}}t | |qS r   )r   ).0ntp)msgr   r   
<dictcomp>=   s    z*_TypedDictMeta.__new__.<locals>.<dictcomp>r   )r"   r   superr   r$   r   r   itemsupdate__dict__r   hasattrr   )r   namebasesr!   r   Ztp_dictZannsbase)	__class__)r(   r   r$   1   s    

z_TypedDictMeta.__new__)T)r   r   __qualname__r$   r   __instancecheck____subclasscheck____classcell__r   r   )r2   r   r   0   s   r   r#   a  A simple typed name space. At runtime it is equivalent to a plain dict.

    TypedDict creates a dictionary type that expects all of its
    instances to have a certain set of keys, with each key
    associated with a value of a consistent type. This expectation
    is not checked at runtime but is only enforced by typecheckers.
    Usage::

        Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})
        a: Point2D = {'x': 1, 'y': 2, 'label': 'good'}  # OK
        b: Point2D = {'z': 3, 'label': 'bad'}           # Fails type check
        assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first')

    The type info could be accessed via Point2D.__annotations__. TypedDict
    supports two additional equivalent forms::

        Point2D = TypedDict('Point2D', x=int, y=int, label=str)

        class Point2D(TypedDict):
            x: int
            y: int
            label: str

    The latter syntax is only supported in Python 3.6+, while two other
    syntax forms work for 3.2+
    c             C   s   | S )zA normal positional argumentr   )typer/   r   r   r   Argk   s    r8   c             C   s   | S )z*A positional argument with a default valuer   )r7   r/   r   r   r   
DefaultArgp   s    r9   c             C   s   | S )zA keyword-only argumentr   )r7   r/   r   r   r   NamedArgu   s    r:   c             C   s   | S )z,A keyword-only argument with a default valuer   )r7   r/   r   r   r   DefaultNamedArgz   s    r;   c             C   s   | S )z*A *args-style variadic positional argumentr   )r7   r   r   r   VarArg   s    r<   c             C   s   | S )z*A **kwargs-style variadic keyword argumentr   )r7   r   r   r   KwArg   s    r=   c               @   s   e Zd ZdS )NoReturnN)r   r   r3   r   r   r   r   r>      s    r>   c             C   s   | S )Nr   )r   r   r   r   trait   s    r?   c              O   s   dd S )Nc             S   s   | S )Nr   )xr   r   r   <lambda>       zmypyc_attr.<locals>.<lambda>r   )attrsZkwattrsr   r   r   
mypyc_attr   s    rD   c               @   s   e Zd Zdd Zdd ZdS )_FlexibleAliasClsAppliedc             C   s
   || _ d S )N)val)selfrF   r   r   r   __init__   s    z!_FlexibleAliasClsApplied.__init__c             C   s   | j S )N)rF   )rG   r   r   r   r   __getitem__   s    z$_FlexibleAliasClsApplied.__getitem__N)r   r   r3   rH   rI   r   r   r   r   rE      s   rE   c               @   s   e Zd Zdd ZdS )_FlexibleAliasClsc             C   s   t |d S )N)rE   )rG   r   r   r   r   rI      s    z_FlexibleAliasCls.__getitem__N)r   r   r3   rI   r   r   r   r   rJ      s   rJ   c               @   s   e Zd Zdd ZdS )_NativeIntMetac             C   s
   t |tS )N)
isinstanceint)r   instr   r   r   r4      s    z _NativeIntMeta.__instancecheck__N)r   r   r3   r4   r   r   r   r   rL      s   rL   c               @   s   e Zd ZdefddZdS )i64r   c             C   s   |t k	rt||S t|S )N)	_sentinelrN   )r   r@   r1   r   r   r   r$      s    
zi64.__new__N)r   r   r3   rQ   r$   r   r   r   r   rP      s   rP   )	metaclassc               @   s   e Zd ZdefddZdS )i32r   c             C   s   |t k	rt||S t|S )N)rQ   rN   )r   r@   r1   r   r   r   r$      s    
zi32.__new__N)r   r   r3   rQ   r$   r   r   r   r   rS      s   rS   c               @   s   e Zd ZdefddZdS )i16r   c             C   s   |t k	rt||S t|S )N)rQ   rN   )r   r@   r1   r   r   r   r$      s    
zi16.__new__N)r   r   r3   rQ   r$   r   r   r   r   rT      s   rT   c               @   s   e Zd ZdefddZdS )u8r   c             C   s   |t k	rt||S t|S )N)rQ   rN   )r   r@   r1   r   r   r   r$      s    
z
u8.__new__N)r   r   r3   rQ   r$   r   r   r   r   rU      s   rU   a/  A native fixed-width integer type when used with mypyc.

        In code not compiled with mypyc, behaves like the 'int' type in these
        runtime contexts:

        * {name}(x[, base=n]) converts a number or string to 'int'
        * isinstance(x, {name}) is the same as isinstance(x, int)
        )r/   )N)#__doc__r   r   r	   r   r   r   r"   r7   r   r   r#   r   r   r8   r9   r:   r;   r<   r=   r>   r?   rD   rE   rJ   ZFlexibleAliasrL   objectrQ   rP   rS   rT   rU   Z	_int_typeformatr   r   r   r   <module>   s>   

	