typing icon indicating copy to clipboard operation
typing copied to clipboard

TypeDict "dict style" positional arguments

Open david-shiko opened this issue 3 years ago • 0 comments

Hi. I'm just curious why passing arguments to TypeDict is strictly constrained. I tried some variants including positional arguments style and failed. It's not reflected in docs or function signature (ctrl + p in Pycharm) https://docs.python.org/3/library/typing.html#typing.TypedDict

In [1]: from typing import TypedDict                                                                                                                                                                       

In [2]:  
   ...: ProfileText = TypedDict(name='ProfileText', fields={'name': str, 'non variable key': str}, total=False)  # Error                                                                                   
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-7d3b7c9254f3> in <module>
----> 1 ProfileText = TypedDict(name='ProfileText', fields={'name': str, 'non variable key': str}, total=False)  # Error

TypeError: _typeddict_new() missing 1 required positional argument: 'typename'

In [3]:  
   ...: ProfileText = TypedDict('ProfileText', {'name': str, 'non variable key': str}, total=False)  # Error                                                                                               

In [4]:  
   ...: ProfileText = TypedDict('ProfileText', {'name': str, 'non variable key': str}, False)  # Error                                                                                                     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-b3b55e028c98> in <module>
----> 1 ProfileText = TypedDict('ProfileText', {'name': str, 'non variable key': str}, False)  # Error

TypeError: _typeddict_new() takes from 2 to 3 positional arguments but 4 were given

In [5]:  

david-shiko avatar Jun 04 '22 14:06 david-shiko