Wrong typing warning for map. (Argument X to "map" has incompatible type overloaded function)
Open
Nobody has claimed this yet.
performance
priority-1-normal
topic-type-variables
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I write this function to check the rightmost common element of two list.
this is the code.
import itertools
def get_common_index(*names: str) -> int:
"""zip genalogy history name tag."""
return max(
i
for i, x in enumerate(
map(
lambda x: len(set(x)) > 1,
list(reversed(list(itertools.zip_longest(*map(reversed, names), fillvalue="0")))),
)
)
if x
)
print(get_common_index("1110111111", "101101111")
It works fine, and the input types are correct.
$ python test.py
5
But mypy raise the following error message.
$ mypy test.py
test.py:24: error: Argument 1 to "map" has incompatible type overloaded function; expected "Callable[[str], Iterator[_T]]"
Is this an error of mypy?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the report with the supplied test.py example and inspect mypy's handling of map, reversed, and itertools.zip_longest overloads. Trace why the callable passed to map is inferred incompatibly, then add or update a regression test showing that valid input types no longer produce this warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100