Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mypy error when mapping a list of values to float

I am trying to evaluate the following statement using mypy:

a = [1,2,3]

b = map(float, a)

this returns the error

Argument 1 to "map" has incompatible type "Type[float]"; expected "Callable[[str], str]"

but at runtime this has no problem executing. What is the reason for this problem?

like image 889
dmmpie Avatar asked Nov 20 '25 19:11

dmmpie


1 Answers

I wasn't able to replicate this either (Python Ver. 3.9.0, mypy Ver. 0.910) so first thing to try would be upgrading to latest versions.

Not quite the same issue, but these issues on the mypy github may be an interesting reference:

https://github.com/python/mypy/issues/6697 (Open)
https://github.com/python/mypy/issues/1855 (Closed)

Based on these, it looks like the following might pass without a mypy error:

b = map(lambda x: float(x), a)
like image 189
ljdyer Avatar answered Nov 22 '25 08:11

ljdyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!