On 01/17/2017 01:37 AM, Antoon Pardon wrote:
Op 17-01-17 om 08:05 schreef Steven D'Aprano:

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

I find those kind of classes annoying as hell and nobody has ever given me a 
good
reason for them.

Subclassing an Enum that has members can be confusing -- subclassed members 
pass isinstance checks but fail to show up in the parent class' iteration.

Subclassing a new data type, such as one with Yes, No, and Maybe, with lots of 
code dealing explicitly with those three singletons, would be confusing if not 
outright broken.

Both those cases are good candidates for disallowing subclassing.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to