python / python/typing

TypeDict "dict style" positional arguments

Offen
#1,204 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

topic: documentation
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
302
Ø Merge
23 Std.
Gemergte PRs (30 T.)
8

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue erwähnt den TypedDict-Einstiegspunkt und die Python-typing-Dokumentation; beginne damit, die gezeigten Schlüsselwort- und Positionsaufrufformen mit dieser Dokumentation zu vergleichen. Bestimme, welche Aufrufkonvention unterstützt werden sollte, und definiere die Fertigstellung als aufeinander abgestimmtes Verhalten, Signaturinformationen, Dokumentation und Tests für die akzeptierte Form.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.