Spec/Conformance: subtyping callables with non-constant parameter mapping.
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Dokumentation
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- python
- Bereich
- documentation, testing-qa
Rechercherichtung
Beginne mit den im Issue verlinkten Regeln zur Zuweisbarkeit von Callables und reproduziere das Beispiel mit mypy, pyright, ty und pyrefly. Das Issue nennt keine Repository-Dateien oder keinen Conformance-Testpfad; der Abschluss hängt davon ab, zu entscheiden, ob die Zuordnung konstanter Parameter in der Spezifikation geklärt oder dieser Fall zu den Conformance-Tests hinzugefügt werden soll.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Consider the example below, which errors with all tested type checkers (mypy/pyright/ty/pyrefly):
from typing import Protocol
class Interval: ...
class Make(Protocol):
def __call__(self, /, lower: float, upper: float) -> Interval: ...
def make_impl(
string_or_lower: str | float | None = None,
/,
lower: float | None = None,
upper: float | None = None,
) -> Interval: ...
def test() -> None:
_f: Make = make_impl # ❌️ type checkers error here.
I believe from a pure type theory POV, this assignment should be legal, because all legal arguments to Make are also legal arguments to make_impl. The spec phrases it in the same spirit:
A callable type B is assignable to a callable type A if the return type of B is assignable to the return type of A and the input signature of B accepts all possible combinations of arguments that the input signature of A accepts. All of the specific assignability rules described below derive from this general rule.
And I couldn't find anything else in https://typing.python.org/en/latest/spec/callables.html#assignability-rules-for-callables that would disallow this assignment.
It seems the type-checkers try to match the KEYWORD_OR_POSITIONAL parameters by name, which is incorrect. Make has 3 legal call signatures:
Make(float, float)Make(float, upper=float)Make(lower=float, upper=float)
and all these 3 call signatures are supported by make_impl, but the parameter mapping is not constant:
make_impl(float, float)->{lower:string_or_lower, upper:lower}make_impl(float, upper=float)->{lower:string_or_lower, upper:upper}make_impl(lower=float, upper=float)->{lower:lower, upper:upper}
So either the spec should demand a constant parameter mapping, or this example should be added to the conformance tests.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
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/typing
-
topic: typing spec
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
topic: typing spec
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
topic: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
topic: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
topic: conformance tests topic: typing spec
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
zostera/django-bootstrap4#894 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
use-agent-os/agent-os#3276 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
NousResearch/hermes-agent#117848 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
zilliztech/memsearch#759 ·