Emulating Final classes in Python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jan 17 02:05:35 EST 2017


I wish to emulate a "final" class using Python, similar to bool:

py> class MyBool(bool):
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type 'bool' is not an acceptable base type


It doesn't have to be absolutely bulletproof, but anyone wanting to subclass my 
class should need to work for it, which hopefully will tell them that they're 
doing something unsupported.

Any hints?




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson



More information about the Python-list mailing list