python / python/mypy

"object" not callable when creating an instance of tuple by using type alias

Open
#10,214 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-type-alias
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Mypy shows an error when creating an instance of tuple by using type alias. Error is not present when doing the same with type alias of a list. It's likely caused by the way tuples are instantiated directly from the __new__ method.

To Reproduce

Vector = tuple[int]

v = Vector([1,2,3])

Expected Behavior

No error

Actual Behavior

error: "object" not callable

Your Environment

  • Mypy version used: 0.812
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.2
  • Operating system and version: Windows 10

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 with the reproducer using Vector = tuple[int] and Vector([1,2,3]), then compare how mypy handles this tuple alias with the equivalent list alias. Run mypy against the example and trace the tuple instantiation and __new__ handling. Done means the valid tuple construction no longer reports "object" not callable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.