Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

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