[New-bugs-announce] [issue35815] Able to instantiate a subclass with abstract methods from __init_subclass__ of the ABC
Jazeps Basko
report at bugs.python.org
Thu Jan 24 02:57:05 EST 2019
New submission from Jazeps Basko <jazeps.basko at gmail.com>:
I am creating and registering singleton instances of subclasses of ABC in the ABC's __init_subclass__ and I just noticed that I am able to instantiate even the classes which have abstract methods.
import abc
class Base(abc.ABC):
def __init_subclass__(cls, **kwargs):
instance = cls()
print(f"Created instance of {cls} easily: {instance}")
@abc.abstractmethod
def do_something(self):
pass
class Derived(Base):
pass
Actual Output:
Created instance of <class '__main__.Derived'> easily: <__main__.Derived object at 0x10a6dd6a0>
Expected Output:
TypeError: Can't instantiate abstract class Derived with abstract methods do_something
----------
messages: 334284
nosy: jbasko
priority: normal
severity: normal
status: open
title: Able to instantiate a subclass with abstract methods from __init_subclass__ of the ABC
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35815>
_______________________________________
More information about the New-bugs-announce
mailing list