Skip to content
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

Join of two type concrete type objects may be considered abstract #3115

Open
JukkaL opened this issue Apr 3, 2017 · 1 comment
Open

Join of two type concrete type objects may be considered abstract #3115

JukkaL opened this issue Apr 3, 2017 · 1 comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-join-v-union Using join vs. using unions

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 3, 2017

Mypy complains about the following code even though it looks fine:

from abc import abstractmethod

class Base:
    @abstractmethod
    def f(self) -> None: pass
class A(Base):
    def f(self) -> None: pass
class B(Base):
    def f(self) -> None: pass

t = [A, B]

t[0]()  # Cannot instantiate abstract class 'Base' with abstract attribute 'f'

It looks like the join of two callables representing type objects should perhaps be Type[x] instead of another callable, since mypy basically assumes that a callable represents a specific type object, not something that can also be any subclass. The same issue probably applies to meets as well.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Apr 3, 2017

Another related problem:

from abc import abstractmethod
from typing import Type

class Base:
    @abstractmethod
    def f(self) -> None: pass
class A(Base):
    def f(self) -> None: pass
class B(Base):
    def f(self) -> None: pass

t: Type[Base] = A if bool() else B  
    # Can only assign non-abstract classes to a variable of type 'Type[rt.Base]'

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 topic-join-v-union Using join vs. using unions
Projects
None yet
Development

No branches or pull requests

3 participants