multiple discarded variables with undescore (_) cause Incompatible types in assignment
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
Here is a silly example:
x = ((1, 'a', 1.4),)
for _, _, y in x:
print(y)
The current output (mypy 0.800)
$ mypy t.py
t.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int")
Found 1 error in 1 file (checked 1 source file)
Here's a real world example:
import pkgutil
from somemod import _plugins
# trigger an import of all of the plugins
# https://github.com/python/mypy/issues/1422
plugins_path: str = _plugins.__path__ # type: ignore
mod_infos = pkgutil.walk_packages(plugins_path, f'{_plugins.__name__}.')
for _, name, _ in mod_infos:
__import__(name, fromlist=['_trash'])
pyupgrade/_data.py:101: error: Incompatible types in assignment (expression has type "bool", variable has type "Union[MetaPathFinder, PathEntryFinder]")
Pitch
The discarded _ variable here is immediately clobbered before it could possibly be read, I'd like this to pass without error
(I couldn't find this searching, though I suspect there's a duplicate -- sorry in advance).
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
Beginne damit, die beiden Beispiele mit mypy 0.800 zu reproduzieren, und untersuche den Typprüfpfad für das Entpacken von Tupeln in for-Schleifenzielen. Erledigt ist die Aufgabe, wenn wiederholte verworfene _-Ziele nicht länger Fehler wegen inkompatibler Zuweisungen verursachen und die Beispiele wie vorgesehen typgeprüft werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers, devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100