Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

No type error detected when function with wrong type is used in the middle of a pipe

Abierto
#2,253 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
tooling

Línea de trabajo

Empieza con el reproductor y ejecuta mypy; después inspecciona los puntos de entrada de la pipeline mencionados en returns/_internal/pipeline/pipe.py y flow.py, junto con el tipado utilizado por pipe. Compara este caso con el caso de error funcional del primer argumento; se considera terminado cuando mypy rechaza la función intermedia incompatible sin romper las pipelines válidas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

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

  • python version: 3.12

  • returns version: returns = {extras = ["compatible-mypy"], version = "^0.26.0"}

  • mypy version: mypy = "^1.17.1"

  • hypothesis version (if any):

  • pytest version (if any):

Lenguaje dominante
Python
Estrellas
4.4k
Forks
154
Merge medio
3 h 5 min
PR fusionados (30 d)
22

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dry-python/returns

Todos los issues de dry-python/returns

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.