python / python/typeshed

The types of `builtins.locals` and `types.FrameType.f_locals` aren't correct

Offen
#14,584 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
5.1k
Forks
2.1k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
82

Beschreibung

builtins.locals and types.FrameType.f_locals are currently typed with dict[str, Any], which is incorrect:

However, I'm not sure what the actual type should be. From what I can gather, the type should implement a mapping interface, with a few (but not all?) MutableMapping methods (PEP 667 describes what these mutable mapping methods are for FrameType.f_locals, but I'm not sure what's exactly expected of builtins.locals()).

In addition, collections.abc.Mapping and collections.abc.MutableMapping themselves are unsuitable, because they're nominal types, although this could be fixed by defining a Protocol which looks like a Mapping.

So, what should the types of builtins.locals and types.FrameType.f_locals be?

Beitragsleitfaden

Beitragsleitfaden öffnen

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

Beginne mit den referenzierten Deklarationen in stdlib/builtins.pyi und stdlib/types.pyi, lies dann die Beschreibung von FrameType.f_locals in PEP 667 und vergleiche sie mit den Laufzeitbeispielen im Issue. Als abgeschlossen gilt die Aufgabe, wenn kompatible Typen sowohl für locals() als auch für f_locals bestimmt und dokumentiert sind, einschließlich der Frage, ob ein strukturelles Mapping-Protokoll erforderlich ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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