mypy confuses dataclass field name with imported function name
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
This standalone file produces the mistaken error models/mypy_bug.py:8: error: "str" not callable:
from dataclasses import dataclass, field
from typing import List
@dataclass
class FilterExpression:
match_type: str
field: str
value: List[str] = field(default_factory=list)
This is because mypy confuses the field "field" and the imported function "field()". Renaming the field removes the error message.
Expected Behavior
This should not be an error.
It's not obvious to me what's correct here, but this code executes as intended in Python 3.8.
So either mypy or Python 3.8 is wrong about this. I choose to file the bug with mypy.
Actual Behavior
mypy gives this error:
models/mypy_bug.py:8: error: "str" not callable
Your Environment
- Mypy version used: 0.800
- Mypy command-line flags: Only
--ignore-missing-imports [paths] - Mypy configuration options from
mypy.ini:strict_optional = False - Python version used: 3.8
- Operating system and version: MacOS 11.2
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 eseguendo mypy 0.800 sull’esempio autonomo models/mypy_bug.py con i flag indicati e l’ambiente Python 3.8, quindi esamina il percorso di risoluzione dei nomi per i campi di dataclass e le funzioni importate. Il lavoro è completato quando l’esempio non segnala più "str" not callable, preservando al contempo la gestione corretta della field()-default factory.
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
- Specificata chiaramente
- Idoneità per principianti
- 35/100