python / python/typing

Wrapper/Proxy Generic Type

Offen
#802 14 Kommentare 37 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

I've been putting some work into typeshed pull requests and I've noticed some places where I could really have used a Proxy Generic class - meaning I can inherit from Proxy[T] and that means that whatever attributes T has, Proxy[T] also has. We don't want to directly mark this as inheritance since then the distinction of a proxy is lost.

The examples I ran into are ProxyType and CallableProxyType in weakref or SynchronizedBase in multiprocessing,csharedtypes.
A big one would be unittest.Mock (See https://github.com/python/mypy/issues/1188).
I'm sure other cases exist,

Advantages:

  • Representing a proxy type easily
  • Allowing type checkers to enforce typing

Disadvantages:

  • Functions that get T won't accept Proxy[T] as an argument. Although the current state is probably something similar.

I'd really like to hear some opinions on the idea.

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

Beginnen Sie mit dem Lesen des Vorschlags und der dazugehörigen Diskussion, einschließlich der Beispiele zu weakref, multiprocessing.sharedctypes und unittest.Mock sowie des verlinkten mypy-Issues. Ein nützliches Ergebnis würde eine Einigung darüber erfordern, ob Proxy[T] zum typing-Design gehört, sowie eine klare Spezifikation seines Verhaltens.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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