Python23: cannot inherit from bool?

FrankS franks at mcs.anl.gov
Tue Jan 21 16:05:11 EST 2003


The purpose was not to change the fundamental behavior of bool, but to add some 
additional methods to create a XML-Schema Boolean-like datatype.

The idea is to map the XSD datatypes as much as possible to python primitive 
datatypes, and to inherit and add methods that would help with writing/parsing 
schemas, xml-serialized data elements, enforce facet constraints and such.

So my (naive) attempt was to define something like:

class XsdBoolean(bool, XsdAnySimpleType):
  ...

The work-around is to derive XsdBoolean from int and achieve essentially the 
same, but it would have been more elegant to derive from bool...

Maybe the restriction should not be on the inheriting itself, but on the 
redefinition of __init__ and/or __new__ , such that you could add additional 
methods that wouldn't mess with the fundamental behavior (?).

Thanks, Frank.


James Kew wrote:
> FrankS wrote:
> 
>>It seems that 2.3 doesn't allow you to inherit from bool:
> 
> 
> I'm not qualified to comment on why it's not allowed, but out of interest:
> why might you want to inherit from bool?
> 
> --
> James Kew
> james.kew at btinternet.com
> 
> 





More information about the Python-list mailing list