B _@sdZddlmZddlZddlmZddZddZd%d d ZGd d d eZ e d e fiZ e e _ de _edfddZedfddZedfddZedfddZefddZefddZGdddZddZdd ZGd!d"d"ZGd#d$d$ZeZdS)&zDefines experimental extensions to the standard "typing" module that are supported by the mypy typechecker. Example usage: from mypy_extensions import TypedDict )AnyN) _type_checkc Cs>y tdjddkrtdWnttfk r8YnXdS)N__name__)abc functoolstypingz4TypedDict does not support instance and class checksF)sys _getframe f_globals TypeErrorAttributeError ValueError)clsotherr3/tmp/pip-unpacked-wheel-fvdunavt/mypy_extensions.py _check_failss  rcOs t||S)N)dict)rargskwargsrrr _dict_newsrc Ksv|dd}|dkr|}n |r&tdt||d}ytdjdd|d<Wnttfk rhYnXt |d |S) NtotalTz@TypedDict takes either a dict or keyword arguments, but not both)__annotations__ __total__rr__main__ __module__r) popr rr r r getr r_TypedDictMeta)rZ _typename_fieldsrrnsrrr_typeddict_new s r"cs&eZdZdfdd ZeZZZS)rTcs|dkr tnt|d<tt|||tf|}|di}dfdd|D}x |D]}||j diqXW||_ t |ds||_ |S)N TypedDict__new__rz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|]\}}t||qSr)r).0ntp)msgrr ?sz*_TypedDictMeta.__new__..r) r"rsuperrr$rritemsupdate__dict__rhasattrr)rnamebasesr!rZtp_dictZannsbase) __class__)r(rr$3s   z_TypedDictMeta.__new__)T)rr __qualname__r$r__instancecheck____subclasscheck__ __classcell__rr)r2rr2srr#aA 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 Python 2.7 and 3.2+ cCs|S)zA normal positional argumentr)typer/rrrArgmsr8cCs|S)z*A positional argument with a default valuer)r7r/rrr DefaultArgrsr9cCs|S)zA keyword-only argumentr)r7r/rrrNamedArgwsr:cCs|S)z,A keyword-only argument with a default valuer)r7r/rrrDefaultNamedArg|sr;cCs|S)z*A *args-style variadic positional argumentr)r7rrrVarArgsr<cCs|S)z*A **kwargs-style variadic keyword argumentr)r7rrrKwArgsr=c@s eZdZdS)NoReturnN)rrr3rrrrr>sr>cCs|S)Nr)rrrrtraitsr?cOsddS)NcSs|S)Nr)xrrrzmypyc_attr..r)attrsZkwattrsrrr mypyc_attrsrDc@seZdZddZddZdS)_FlexibleAliasClsAppliedcCs ||_dS)N)val)selfrFrrr__init__sz!_FlexibleAliasClsApplied.__init__cCs|jS)N)rF)rGrrrr __getitem__sz$_FlexibleAliasClsApplied.__getitem__N)rrr3rHrIrrrrrEsrEc@seZdZddZdS)_FlexibleAliasClscCs t|dS)N)rE)rGrrrrrIsz_FlexibleAliasCls.__getitem__N)rrr3rIrrrrrJsrJ)N)__doc__rrr rrrr"r7rrr#rrr8r9r:r;r<r=r>r?rDrErJZ FlexibleAliasrrrrs,