python / python/mypy

Odd error message for invalid use of tuple(): expected "Iterable[Never]"

Open
#19,098 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-error-reporting
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

tuple(1) is invalid, of course. But what error message does it bring?

main.py:1: error: Argument 1 to "tuple" has incompatible type "int"; expected "Iterable[Never]"  [arg-type]

Well that's odd! Considering that it can take iterables of all sorts of things, and not... impossible things.

In fact, this has to be wrong, because when I make my own function with Iterable[Never] argument, it doesn't like taking iterables of other things

from typing import Iterable, Never

def f(a: Iterable[Never]) -> None:
    pass

f([1,2,3]) # main.py:6: error: Argument 1 to "f" has incompatible type "list[int]"; expected "Iterable[Never]"  [arg-type]

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 diagnostic in main.py with tuple(1), then compare it with the Iterable[Never] example shown in the issue. Trace the type information used for tuple() and determine why its invalid argument is reported as Iterable[Never]; done means the diagnostic no longer presents that misleading expectation and relevant checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.