New type inference processes `itertools.groupby` key as `Any`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beschreibung
Bug Report
Given code like:
import itertools
for grouper, members in itertools.groupby('aBcD', key=lambda x: x.isupper()):
reveal_type(grouper)
reveal_type(members)
Running mypy at 1.6.1 without arguments or on any more recent version with --old-type-inference results in the expected output:
$ mypy demo.py --old-type-inference
demo.py:4: note: Revealed type is "builtins.bool"
demo.py:5: note: Revealed type is "typing.Iterator[builtins.str]"
Success: no issues found in 1 source file
However on more recent versions without --old-type-inference we get:
$ mypy demo.py
demo.py:4: note: Revealed type is "Any"
demo.py:5: note: Revealed type is "typing.Iterator[builtins.str]"
Success: no issues found in 1 source file
Original case
In my original use-case, the grouper key was a tuple which I was spraying into a function call:
for source, errors_group in itertools.groupby(errors, key=lambda x: x.source):
messages = [x.message for x in errors_group]
report_errors(*source, messages)
mypy was previously happy with that, however since the change to process the grouper key as Any I now get errors:
sr/comp/validation.py:113:13: error: Too many arguments for "report_errors" [call-arg]
Your Environment
- Mypy version used: bisected to 93d4cb0a2ef1723ce92f39ae61fe6a0c010eb90b being the commit which introduced the change (from which I then tested
--old-type-inference); I realise that commit doesn't introduce the new inference logic, though I haven't chased beyond that commit - Mypy command-line flags: none required
- Mypy configuration options from
mypy.ini(and other config files): none required - Python version used: 3.10
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 die Reproduktion in demo.py sowohl mit als auch ohne --old-type-inference aus und untersuche anschließend die Änderung rund um den Commit 93d4cb0a2ef1723ce92f39ae61fe6a0c010eb90b. Als erledigt gilt die Aufgabe, wenn der Schlüssel von itertools.groupby als builtins.bool offengelegt wird, während die Elemente typing.Iterator[builtins.str] bleiben, ohne den im ursprünglichen Fall gezeigten Aufruf mit Tupel-Schlüssel zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 30/100