Emulating Final classes in Python

Steve D'Aprano steve+python at pearwood.info
Tue Jan 17 18:25:36 EST 2017

On Tue, 17 Jan 2017 08:54 pm, Erik wrote:

> Hi Steven,
> On 17/01/17 07:05, Steven D'Aprano wrote:
>> I wish to emulate a "final" class using Python, similar to bool:
> [snip]
>> 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.
> When someone brings up something like this you usually quote the
> "consenting adults" argument, so I'll throw it back at you - why not
> just add it to your documentation?

A very good question :-)

Why am I doing this? Part of the answer is simply because I can. I want to
see how far I can go to lock down the class in pure Python code.

“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

More information about the Python-list mailing list