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

Skip to content

Instantiating concrete classes fails check in some cases #6586

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
majutsushi opened this issue Mar 24, 2019 · 1 comment
Closed

Instantiating concrete classes fails check in some cases #6586

majutsushi opened this issue Mar 24, 2019 · 1 comment

Comments

@majutsushi
Copy link

majutsushi commented Mar 24, 2019

#1843/#2853 added support for instantiating variables with an abstract type, under the assumption that it will always be applied to a concrete subclass. However, this doesn't seem to work in all cases:

Given

class Base(ABC):
    @abstractmethod
    def m(self) -> None:
        pass

class A(Base):
    def m(self) -> None:
        pass

class B(Base):
    def m(self) -> None:
        pass

Then

var: Type[Base]
if "foo" == "bar":
    var = A
elif "foo" == "baz":
    var = B
else:
    raise RuntimeError()

var()  # error: Cannot instantiate abstract class 'Base' with abstract attribute 'm'

As far as I understand it the last line shouldn't result in an error.

If I remove class B (and the corresponding elif) I don't get an error. Interestingly, if I remove the whole if block I also don't get an error.

This is with version 0.670.

@ilevkivskyi
Copy link
Member

This code (and variations you describe) pass without errors on master, so I think this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants