Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adamtheturtle opened this issue Jun 2, 2018 · 2 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal

Comments

@adamtheturtle
Copy link

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.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal false-positive mypy gave an error on correct code labels Aug 15, 2018
@achimnol
Copy link
Contributor

achimnol commented Dec 2, 2019

I just encountered the same issue with Python 3.8.0 and mypy 0.750.
Maybe the solution for #6586 should be expanded to dictionary values and other generics.

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 2, 2019

Closing in favor of #8050, as the newer issue has a workaround.

@JukkaL JukkaL closed this as completed Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal
Projects
None yet
Development

No branches or pull requests

4 participants