Skip to content

TypeDict "dict style" positional arguments #1204

@david-shiko

Description

@david-shiko

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]:  

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions