-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
When an abstract class defines __new__
(note, not __init__
) method, mypy
produces error when that class is instantiated, even though __new__()
does not imply instantiation.
To Reproduce
from abc import ABCMeta, abstractmethod
class Abstract(metaclass=ABCMeta):
def __new__(cls) -> "Abstract":
return super().__new__(Concrete)
@abstractmethod
def hello(self) -> int:
...
class Concrete(Abstract):
def hello(self) -> int:
return 0
x = Abstract()
print(x.hello())
Expected Behavior
No errors reported when checked with mypy. Calling a class with __new__
method shuld be effectively treated as just calling a simple method, like
def make_abstract() -> "Abstract":
return Concrete()
Actual Behavior
error message is printed:
error: Cannot instantiate abstract class "Abstract" with abstract attribute "hello" [abstract]
Your Environment
- Mypy version used: mypy-0.991
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.10.6
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong