Skip to content

Passing a type as the first argument of map #8113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cjolowicz opened this issue Dec 9, 2019 · 3 comments
Closed

Passing a type as the first argument of map #8113

cjolowicz opened this issue Dec 9, 2019 · 3 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code

Comments

@cjolowicz
Copy link
Contributor

The following expression should type-check fine, right?

map(list, [{1}])

The intended use is to convert (iterables of) sets to (iterables of) lists, e.g. to support slicing.

I'm getting this error:

main.py:1: error: Argument 1 to "map" has incompatible type "Type[List[Any]]"; expected "Callable[[Set[int]], List[_T]]"
Found 1 error in 1 file (checked 1 source file)

This issue seems related to #3092.

@msullivan msullivan added bug mypy got something wrong false-positive mypy gave an error on correct code labels Dec 12, 2019
@msullivan
Copy link
Collaborator

It looks like there are a bunch of bugs having to do with using types as functions in generic situations.

@pcworld
Copy link

pcworld commented Sep 15, 2021

As a workaround, the following passes with Python 3.9: map(list[int], [{1}])
On earlier Python versions, the following works: map(lambda i: list(i), [{1}])

@ilevkivskyi
Copy link
Member

This now works properly (most likely by polymorphic inference).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code
Projects
None yet
Development

No branches or pull requests

4 participants