[pyar] Por qué no se puede extender la clase bool?

Terry Reedy tjreedy en udel.edu
Jue Jun 28 04:58:53 ART 2012


On 6/16/2012 7:42 AM, Juanjo Conti wrote:

> Una respuesta que cita a Guido está buena:
>
> '''
> I thought about this last night, and realized that you shouldn't be
> allowed to subclass bool at all! A subclass would only be useful when
> it has instances, but the mere existance of an instance of a subclass
> of bool would break the invariant that True and False are the only
> instances of bool! (An instance of a subclass of C is also an instance
> of C.) I think it's important not to provide a backdoor to create
> additional bool instances, so I think bool should not be subclassable.
> '''

bool no es unico

 >>> class MyNone(type(None)): pass

Traceback (most recent call last):
   File "<pyshell#1>", line 1, in <module>
     class MyNone(type(None)): pass
TypeError: type 'NoneType' is not an acceptable base type

 >>> class MNI(type(NotImplemented)): pass

Traceback (most recent call last):
   File "<pyshell#3>", line 1, in <module>
     class MNI(type(NotImplemented)): pass
TypeError: type 'NotImplementedType' is not an acceptable base type


-- 
Terry Jan Reedy







More information about the pyar mailing list