Standard library map on bound function
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne mit der gemeldeten test.py-Reproduktion und konzentriere dich auf das Zusammenspiel von returns.pointfree.bind, ResultE und Pythons integriertem map. Vergleiche die von mypy inferierten Typen mit der funktionierenden for-Schleife und den expliziten g-Alternativen; abgeschlossen ist die Arbeit, wenn das ursprüngliche Beispiel map(bind(g), map(f, range(3))) ohne Fehler die Typprüfung besteht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug report
Mypy does not appear to correctly handle the standard library map function over an iterable of containers that returns an iterable of containers, when the function being mapped over the data has had returns.pointfree.bind applied to it. The same code when used without map (by explicit use of a for-loop) or a bind (by explicitly handling a container input) will not result in an error.
What's wrong
Code to reproduce issue
from typing import Iterable
from returns.pointfree import bind
from returns.result import ResultE
from returns.result import safe
@safe
def f(x: int) -> str:
return str(x)
@safe
def g(x: str) -> int:
return int(x)
def h(xs: Iterable[ResultE[int]]) -> None:
for x in xs:
print(x.unwrap())
if __name__ == "__main__":
h(map(bind(g), map(f, range(3))))
Mypy output
$ mypy test.py
test.py:24:11: error: Argument 1 to "map" has incompatible type "Kinded[Callable[[KindN[Result[Any, Any], str, Exception, NoReturn]], KindN[Result[Any, Any], int, Exception, NoReturn]]]"; expected "Callable[[Result[str, Exception]], Res
ult[int, Exception]]" [arg-type]
test.py:24:11: note: "Kinded[Callable[[KindN[Result[Any, Any], str, Exception, NoReturn]], KindN[Result[Any, Any], int, Exception, NoReturn]]].__call__" has type "Callable[[KindN[Result[Any, Any], str, Exception, NoReturn]], KindN[Resul
t[Any, Any], int, Exception, NoReturn]]"
Found 1 error in 1 file (checked 1 source file)
Python output
$ python test.py
0
1
2
How it should be
When the h function is replaced with a for-loop in __main__ no issues are reported by Mypy and the code executes correctly:
if __name__ == "__main__":
for x in map(f, range(3)):
print(x.bind(g).unwrap())
Can also fix the issue by swapping out the g function:
def g(x: ResultE[str]) -> ResultE[int]:
return x.map(int)
<snip>
if __name__ == "__main__":
h(map(g, map(f, range(3))))
System information
pythonversion: 3.8.6returnsversion: 0.15.0mypyversion: 0.800 (also observed in v0.782 due toclassesslibrary dependency)
- Vorherrschende Sprache
- Python
- Sterne
- 4.4k
- Forks
- 154
- Ø Merge
- 3 Std. 5 Min.
- Gemergte PRs (30 T.)
- 22
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus dry-python/returns
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
dry-python/returns#2394 · 1 Reaktion ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
dry-python/returns#2365 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
dry-python/returns#2355 · 1 Kommentar ·
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
dry-python/returns#2295 · 4 Kommentare · 1 Reaktion ·
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
dry-python/returns#2253 · 2 Kommentare ·
Alle Issues in dry-python/returns
Ähnliche Issues
-
agent-ready documentation needs-triage
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
instance instance add
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
searxng/searx-instances#939 · 1 Kommentar ·
-
area-deployment area-integrations triage:bot-seen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 86/100