Unpacking int arguments to datetime.datetime gives a complaint about tzinfo
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
mypy complains about this line of code. First I don't understand why and second I cannot bring it to accept it, even when including tzinfo=None in the parameter list.
# error: "datetime" gets multiple values for keyword argument "tzinfo"
dt.datetime(*split_int_string(date, 4, 6, 8), *split_int_string(time, 2, 4))
# or
# error: "datetime" gets multiple values for keyword argument "tzinfo"
dt.datetime(*split_int_string(date, 4, 6, 8), *split_int_string(time, 2, 4), tzinfo=None)
Why does mypy think tzinfo would already be used, it cannot be from a List[int]. The behavior when running is as expected.
The helper function is annotated like this:
def split_int_string(digits: str, *at: int) -> List[int]:
"""
Split a string at given indices and parse the parts to int.
"""
# Make a canonical representation.
split: List[int] = sorted(at)
if not split or split[0] != 0:
split.insert(0, 0)
if split[-1] != len(digits):
split.append(len(digits))
return [int(digits[split[i - 1] : split[i]]) for i in range(1, len(split))]
To Reproduce
(Write your steps here:)
- Paste from here into a file.
- Run with
python3, it works. - Pass to
mypyto see the error.
Expected Behavior
I expect not to get a typing error for that line.
Actual Behavior
It prints
error: Argument 1 to "datetime" has incompatible type "*List[int]"; expected "Optional[tzinfo]"
or
error: "datetime" gets multiple values for keyword argument "tzinfo"
depending on whether one also adds the tzinfo=None or not.
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.8.6
- Operating system and version: Linux CL003356 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Guida per i contributori
Apri la guida per i contributori
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.
Direzione di ricerca
Inizia con il riproduttore incollato collegato nell’issue e analizza come mypy gestisce le chiamate a datetime.datetime con più argomenti List[int] espansi. Conferma la diagnosi relativa a tzinfo, quindi confrontala con il comportamento a runtime mostrato nel report. Il lavoro è completato quando la chiamata valida non produce più l’errore di tipizzazione errato, mentre i conflitti reali tra argomenti continuano a essere diagnosticati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100