Question on ABC classes

Marco Sulla Marco.Sulla.Python at gmail.com
Thu Oct 22 16:18:40 EDT 2020


On Thu, 22 Oct 2020 at 22:09, Marco Sulla <Marco.Sulla.Python at gmail.com>
wrote:

> Not sure because I never tried or needed, but if no @abstractsomething in
> A is defined and your B class is a subclass of A, B should be an abstract
> class, not a concrete class.
>

Now I'm sure:

>>> from abc import ABC, abstractmethod
>>> class A(ABC): pass
...
>>> class B(A):
...     @abstractmethod
...     def hello(self):
...             print("hello")
...
>>> B()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class B with abstract methods hello

>
>


More information about the Python-list mailing list