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

Standard library map on bound function

Abierto
#807 4 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
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
tooling

Línea de trabajo

Comienza con la reproducción reportada en test.py, centrándote en la interacción entre returns.pointfree.bind, ResultE y el map integrado de Python. Compara los tipos inferidos por mypy con el bucle for funcional y las alternativas explícitas de g; se considera terminado cuando el ejemplo original map(bind(g), map(f, range(3))) pasa la comprobación de tipos sin errores.

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

Descripción

bug

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

  • python version: 3.8.6
  • returns version: 0.15.0
  • mypy version: 0.800 (also observed in v0.782 due to classess library dependency)
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.