`functools.partialmethod` loses return type and callable signature information
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- developer-experience
Rechercherichtung
Start by reading the existing functools.partialmethod stub in typeshed and compare its descriptor behavior with the examples in the issue. Check the relevant stub tests for callable and descriptor typing; the issue does not name a test file. Done means preserving return-type and descriptor-binding information as far as current typing support allows, while acknowledging that a fully precise residual signature needs typing-spec support.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
For code of this shape:
from functools import partialmethod
def pprint(arg: object, /, *, options: dict) -> str:
return "dummy"
class Foo: ...
class Bar: ...
Bar.__repr__ = partialmethod(pprint, options={})
it is difficult for type checkers to verify that partialmethod is compatible with the target method since it is currently typed with only a return-type parameter:
class partialmethod(Generic[_T]):
...
def __get__(self, obj: Any, cls: type[Any] | None = None) -> Callable[..., _T]: ...
The current stub does not preserve the wrapped callable’s parameters or receiver type, so type checkers cannot model these class and instance access forms even though this ebhaviour is valid at runtime, and partialmethod is a descriptor:
Bar.__repr__ # T: (self: Bar) -> str
Bar().__repr__ # T: () -> str
This forces Pyrefly and Pyright to reject this valid code. Mypy on the other hand, looks at stub’s descriptor fallback (Any) and infers partialmethod[Any] even when the wrapped callable returns str.
We should preserve descriptor binding and as much callable information as possible, while accepting that a fully precise residual signature needs typing-spec support.
Born from Pyrefly issue, https://github.com/facebook/pyrefly/issues/5138
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 2 T. 7 Min.
- Gemergte PRs (30 T.)
- 116
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/typeshed
-
`networkx.set_edge_attributes` should support scalar value + nameEvtl. vergeben @Fire162 hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
Maintainer antworten meist innerhalb von 1 Tag
-
false alarm on decode callEvtl. vergeben @jw9829 hat das vor 37 Tagen übernommen. Offenhelp wanted stubs: false positive
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
python/typeshed#16441 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Don't run pyright basic checks on projects with strict pyright settings in CIEvtl. vergeben @Mohith1612 hat das vor 73 Tagen übernommen. Offenproject: infrastructure
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
python/typeshed#16005 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
stubs: improvement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
python/typeshed#15548 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
stubs: improvement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
python/typeshed#15529 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in python/typeshed
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
earthtojake/text-to-cad#758 ·
Maintainer antworten meist innerhalb von 1 Tag
-
domain:upgrades enhancement needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
gke-labs/kube-agents#4634 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
agardnerIT/opamp-server-py#116 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
elviskahoro/sdk-python-attio#144 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag