Skip to content

Mapping to abs doesn't work #6697

Closed
Closed
@YtvwlD

Description

@YtvwlD

I first encountered this issue with Python 3.6.7 and mypy 0.560 from my distribution's repositories, but it also occurs on Python 3.7 and mypy 0.701, and the current master.

This is the code in question:

map(abs, [1])

It works, of course. But running mypy on it raises an error:

test.py:2: error: Argument 1 to "map" has incompatible type "Callable[[SupportsAbs[_T]], _T]"; expected "Callable[[int], _T]"

If I change it to the following code, there are no errors:

map(lambda x: abs(x), [1])

(This is a minimal example, my original code was something like sum(map(abs, list_of_floats)).)

So, what's the problem here? int and float have .__abs__.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions