New submission from Jazeps Basko <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue35815>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com