python / python/typing

TypeDict "dict style" positional arguments

Open
#1,204 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic: documentation
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue mentions the TypedDict entry point and the Python typing documentation; start by comparing the shown keyword and positional call forms with that documentation. Determine which calling convention should be supported, then define completion as aligned behavior, signature information, documentation, and tests for the accepted form.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.