No type error detected when function with wrong type is used in the middle of a pipe
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia con il riproduttore ed esegui mypy, quindi ispeziona i punti di ingresso della pipeline menzionati in returns/_internal/pipeline/pipe.py e flow.py, insieme alla tipizzazione usata da pipe. Confronta questo caso con il caso di errore funzionante del primo argomento; il lavoro è completato quando mypy rifiuta la funzione intermedia incompatibile senza compromettere le pipeline valide.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug report
Thank you for this project! I'm new to Python, so I apologize if I've overlooked something.
What's wrong
from collections.abc import Callable
from returns.pipeline import flow, pipe
from returns.pointfree import map_
from returns.result import Success
def get_data(data: str) -> str:
return "200" + data
def do_more(data: int) -> int:
return data - 300
def transform(s: str) -> str:
return f"transformed: {s}"
my_pipe: Callable[[str], str] = pipe(get_data, do_more, transform)
print(flow(Success("500"), map_(my_pipe)))
Gives following runtime error while mypy doesn't complain:
(py-starter) python-boilerplate > python working.py
Traceback (most recent call last):
File "/Users/hoschi/repos/python-boilerplate/working.py", line 22, in <module>
print(flow(Success("500"), map_(my_pipe)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 50, in flow
return reduce( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 51, in <lambda>
lambda composed, function: function(composed), # type: ignore
^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/pointfree/map.py", line 55, in factory
return container.map(function)
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/result.py", line 426, in map
return Success(function(self._inner_value))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/pipe.py", line 34, in <lambda>
return lambda instance: flow(instance, *functions)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 50, in flow
return reduce( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 51, in <lambda>
lambda composed, function: function(composed), # type: ignore
^^^^^^^^^^^^^^^^^^
File "/Users/hoschi/repos/python-boilerplate/working.py", line 13, in do_more
return data - 300
~~~~~^~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'
How is that should be
Mypy should detect the error. It can detect the error when the problem function is used at first arg: pipe(do_more, get_data, transform)
System information
-
pythonversion: 3.12 -
returnsversion:returns = {extras = ["compatible-mypy"], version = "^0.26.0"} -
mypyversion:mypy = "^1.17.1" -
hypothesisversion (if any): -
pytestversion (if any):
- Lingua principale
- Python
- Stelle
- 4.4k
- Fork
- 154
- Merge medio
- 3h 5m
- PR unite (30g)
- 22
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.
Altre issue di dry-python/returns
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
dry-python/returns#2394 · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
dry-python/returns#2365 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
dry-python/returns#2355 · 1 commento ·
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
dry-python/returns#2295 · 4 commenti · 1 reazione ·
-
Incorrect result type for `returns.curry.partial` with keyword arguments for positional parameters Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
dry-python/returns#2191 · 1 commento ·
Tutte le issue di dry-python/returns
Issue simili
-
bug confirmed issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
open-webui/open-webui#30750 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100