Skip to content

Concrete class considered abstract when base class has additional python type  #14067

@AngryUbuntuNerd

Description

@AngryUbuntuNerd

Bug Report

When using a TypeVar from an abstract class, and the abstract class additionally inherits from some integrated types (I found dict, int, str, set; not float), mypy incorrectly alarms about instantiating an abstract class.

To Reproduce

from abc import ABC, abstractmethod
from typing import TypeVar, Type


class User(ABC, dict):  # removing dict makes mypy happy
    @abstractmethod
    def method(self):
        ...


class BasicUser(User):
    def method(self):
        print('basic')


U = TypeVar('U', bound=User)


def new_user(user_class: Type[U]) -> U:
  user = user_class()
  return user


joe = new_user(BasicUser)

Expected Behavior

It should not report an error, as it does not when inheriting from another class or just ABC.

Actual Behavior

test.py:20: error: Cannot instantiate abstract class "User" with abstract attribute "method" [abstract]

Your Environment

  • Mypy version used: 0.990
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions