Skip to content

Value of type variable "Self" of "__new__" of "tuple" cannot be <some subclass of typing.Tuple> #14890

@robsdedude

Description

@robsdedude

Bug Report

Starting with version 1.1, I get an error when calling Tuple[float, ...]'s __new__.

To Reproduce

from typing import Iterable, Tuple


class Foo(Tuple[float, ...]):
    def __new__(cls, values: Iterable[float]) -> Foo:
        return tuple.__new__(cls, map(float, values))

Expected Behavior

This should not be rejected by mypy (and it wasn't until version 1.1.1)

Actual Behavior

Starting with mypy 1.1.1, mypy complains with the following error

test.py:8: error: Value of type variable "Self" of "__new__" of "tuple" cannot be "Foo"  [type-var]

Remark
Changing tuple.__new__ to super().__new__ makes mypy complain (both mypy version 1.1.1 and 1.0.1) with

Argument 1 to "map" has incompatible type "Type[float]"; expected "Callable[[float], _T_co]"

Your Environment

  • Mypy version used: 1.1.1 and 1.0.1
  • Mypy command-line flags: none
  • Mypy configuration options from pyproject.toml:
    [tool.mypy]
    
    [[tool.mypy.overrides]]
    module = "pandas.*"
    ignore_missing_imports = true
  • Python version used: tested on 3.8 and 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-self-typesTypes for self

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions