Ben Chuanlong Du's Blog

It is never too late to learn.

Prevent a Class from Direct Instantiation in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Inherit the class abc.ABC

from abc import ABC

class MyABC(ABC): pass

Define a Customized __new__ Method

Reference

https://docs.python.org/3/library/abc.html

Preventing a class from direct instantiation in Python

Comments