python / python/mypy

super(type, cls).__new__ saying not an instance when it is

Open
#7,595 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-1-normal
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

When upgrading to the latest mypy I started getting a weird new error. Here's a simplified example:

class X:
    def __new__(cls) -> "X":
        return super(type, cls).__new__(cls)    # error: Argument 2 for "super" not an instance of argument 1

However:

>>> isinstance(X, type) 
True

My settings: mypy 0.730

[mypy]
python_version=3.6
incremental=True
ignore_missing_imports=True
follow_imports=normal
warn_redundant_casts=True
warn_unused_ignores=True
strict_optional=True
no_implicit_optional=True
disallow_untyped_defs=True
disallow_any_generics=True

(Note: I'm using super to skip an inherited __new__ when I create the object.)

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 running the minimal X.new example with mypy 0.730 and inspect how the checker handles super(type, cls) and the new call. No source files or tests are named in the report; done means the valid example no longer produces the instance-type error, with coverage for this regression.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.