Skip to content

Fix abstract attribute errors with Any base class #4230

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

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ def check_call(self, callee: Type, args: List[Expression],

if (callee.is_type_obj() and callee.type_object().is_abstract
# Exceptions for Type[...] and classmethod first argument
and not callee.from_type_type and not callee.is_classmethod_class):
and not callee.from_type_type and not callee.is_classmethod_class
and not callee.type_object().fallback_to_any):
type = callee.type_object()
self.msg.cannot_instantiate_abstract_class(
callee.type_object().name(), type.abstract_attributes,
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-abstract.test
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,21 @@ class C:
def __add__(self, other: int) -> B: pass
[out]

[case testAbstractClassWithAnyBase]
from typing import Any
from abc import abstractmethod, ABCMeta

A: Any

class D(metaclass=ABCMeta):
@abstractmethod
def f(self) -> None: pass

class C(A, D):
pass

C() # A might implement 'f'


-- Abstract properties
-- -------------------
Expand Down