Skip to content

Error when choosing subclass of ABC from more than one option in a dictionary #5135

Closed
@adamtheturtle

Description

@adamtheturtle

Are you reporting a bug, or opening a feature request?

Reporting a bug.

Please insert below the code you are checking with mypy

import abc

class A(abc.ABC):

    @abc.abstractmethod
    def foo(self):
        pass

class B(A):

    def foo(self):
        pass

class C(A):

    def foo(self):
        pass

cls_b = {1: B}[1]
cls_b()

cls_c = {2: C}[2]
cls_c()

cls_b_2 = {1: B, 2: C}[1]
# mypy error here:
# example.py:26: error: Cannot instantiate abstract class 'A' with abstract attribute 'foo'
cls_b_2()

What is the actual behavior/output?

# example.py:26: error: Cannot instantiate abstract class 'A' with abstract attribute 'foo'

What is the behavior/output you expect?

No error.

What are the versions of mypy and Python you are using?

mypy 0.600
Python 3.6.5

Do you see the same issue after installing mypy from Git master?

Yes

What are the mypy flags you are using? (For example --strict-optional)

No flags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions