[@overload]: What is the effect of the *implementation* type-signature?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Documentazione
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- python
- Ambito
- documentation
Direzione di ricerca
Inizia con gli esempi di @overload presenti in questa issue ed eseguili nel Pyright playground collegato, quindi confronta i risultati con mypy. Esamina come i due strumenti interpretano le firme di implementazione e gli elenchi di overload. Il lavoro è completato quando si è raggiunta una spiegazione condivisa della semantica e sono stati documentati il comportamento previsto e gli esempi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
One thing that I've found underspecified when using @overload is what the type signature of the actual function should be.
For example, let's say I have a function like:
from typing import overload, Literal
@overload
def f(x: int, z: Literal[True]) -> str: ...
@overload
def f(x: int, z: Literal[False] = ...) -> int: ...
def f(x: int, z: bool = False) -> str | int:
if z:
return "hello"
return 1
What is the effect of the last line? In particular:
- The documentation and examples often just use no annotations for the implementation signature (
def f(x, z):). Is that the right thing to do (I sometimes getOverloaded implementation is not consistent with signature of overload 1errors if I leave out the type annotations)? - If I do specify types on the last, do I also have to add it to
@overloadlist -- in other words:
@overload
def f(x: int, z: Literal[True]) -> str: ...
@overload
def f(x: int, z: Literal[False] = ...) -> int: ...
@overload
def f(x: int, z: bool = ...) -> str | int # is this overload necessary?
def f(x: int, z: bool = False) -> str | int:
if z:
return "hello"
return 1
Both pyright and mypy seem to interpret things differently with and without it (e.g. see this play link).
I understand that @overload is a complicated feature, but I'm hoping this is a small corner we can start with.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/typing
-
topic: typing spec
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
topic: typing spec
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
topic: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
topic: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
topic: conformance tests topic: typing spec
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
Tutte le issue di python/typing
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
canonical/paas-charm#368 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
addition to tracking list Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
StevenBlack/hosts#3256 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
qualcomm/qai-appbuilder#275 ·