Question on ABC classes

Julio Di Egidio julio at diegidio.name
Thu Oct 22 12:25:34 EDT 2020


Hello guys,

I am professional programmer but quite new to Python,
and I am trying to get the grips of some peculiarities
of the language.

Here is a basic question: if I define an ABC class,
I can still instantiate the class unless there are
abstract methods defined in the class.

(In the typical OO language the class would be not
instantiable, period, since it's "abstract".  But
this is not so in Python, to the point that, also
for uniformity, I am feeling compelled to define an
@abstractmethod __init__ in my ABC classes, whether
they need one or not, and whether there are other
abstract methods in the class or not.)

Now, I do read in the docs that that is as intended,
but I am not understanding the rationale of it: why
only if there are abstract methods defined in an ABC
class is instantiation disallowed?  IOW, why isn't
subclassing from ABC enough?

Thanks for any enlightenment,

Julio


More information about the Python-list mailing list