Message334284
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 |
|
Date |
User |
Action |
Args |
2019-01-24 07:57:07 | jbasko | set | recipients:
+ jbasko |
2019-01-24 07:57:05 | jbasko | set | messageid: <1548316625.2.0.852101004839.issue35815@roundup.psfhosted.org> |
2019-01-24 07:57:05 | jbasko | link | issue35815 messages |
2019-01-24 07:57:05 | jbasko | create | |
|