Reject arguments that are both keyword and positional only
Offen
Dieses Issue hat noch niemand übernommen.
bug
priority-2-low
topic-calls
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
I tried to use Calalble protocol like this:
from typing import Callable, Protocol
class F(Protocol):
def __call__(self, *__args: str, __arg: int) -> int: ...
def f(*__args: str, __arg: int) -> int: ...
f_: F = f
but it fails with quite confusing message:
error: Incompatible types in assignment (expression has type "Callable[[VarArg(str), NamedArg(int)], int]", variable has type "F")
note: "F.__call__" has type "Callable[[VarArg(str), NamedArg(int)], int]"
Found 1 error in 1 file (checked 1 source file)
If I move varargs, things pass:
class G(Protocol):
def __call__(self, __arg: int, *__args: str) -> int: ...
def g(__arg: int, *__args: str) -> int: ...
g_: G = g
I cannot say if this is a bug, or expected behaviour with confusing message.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst mypy für die beiden Callable/Protocol-Reproduktionen im Issue aus und vergleiche die Diagnosen zur Zuweisung. Verfolge die Behandlung von __args und __arg bei der Callable-Kompatibilität und überprüfe anschließend, dass Argumente, die sowohl als Keyword- als auch als Positionsargument behandelt werden, mit einer eindeutigen Diagnose abgelehnt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100