Unsupported operand types for + (List[A] and List[B]) when B extends A

Open
#3,933 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
devtools

Research direction

Start by reproducing the reported example with List[A] and List[B], where B extends A, and confirm the current type-checker error. Review the surrounding type-inference and list-operator behavior to determine the intended result; done means the example has a documented or tested resolution consistent with the chosen typing semantics.

Written by the indexing model from the issue text.

Description

feature needs discussion

If I have:

Class A:

Class B(A):

Then If I try to add lists of these two objects you get the following mypy error:
error: Unsupported operand types for + (List[A] and List[B])

Any ideas for a work around on this one? Surely the inferred type should be List[Union[A, B]

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.