python / python/mypy

Inconsistent behavior with list(reduce(...))

Open
#8,861 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

from functools import reduce

tmp = reduce(lambda x, y: x + y, [[1], [2]])
# this works fine
result = list(tmp) 

# but this one produces an error:
#  Unsupported left operand type for + ("Iterable[int]")
result = list(reduce(lambda x, y: x + y, [[1], [2]]))
$ mypy --version
mypy 0.770

Python version:

>>> sys.version
'3.8.2 (default, May 20 2020, 18:13:32) \n[GCC 7.5.0]'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two reduce/list snippets with the reported mypy 0.770 environment, then trace how their inferred types differ. Done means the equivalent forms receive consistent, correct type-checking behavior; no source file or test is identified in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.