A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-February/042537.html below:

[Python-Dev] bool does not want to be subclassed?

[Python-Dev] bool does not want to be subclassed?Bob Ippolito bob at redivi.com
Thu Feb 12 14:58:42 EST 2004
On Feb 12, 2004, at 2:41 PM, François Pinard wrote:

> Hi, people.  I just noticed this:
>
>
>>>> class booleen(bool):
> ...   def __repr__(self):
> ...     if self:
> ...         return "Vrai"
> ...     return "Faux"
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: type 'bool' is not an acceptable base type
>>>>
>
>
> and am a bit surprised that `bool' refuses to be sub-classed.  Not that
> I cannot live without it, of course!  But it might be useful being
> able to "cast" a `bool' into something for which I could control the
> representation, while keeping all other properties of `bool'.
>
> Is there a deep reason behind the forbidding?  Or was it merely for
> possibly protecting users against themselves? :-) For me, this is a
> question, much more than an issue.  Yet, if there is no deep reason,
> maybe the forbidding could be lifted?

Probably because bool is supposed to only have two values, True or 
False.. not True, False, Yes, No, Vrai, Faux. You can subclass int and 
implement __nonzero__ just like bool does (in fact, bool does little 
more than that).

Is there a good reason for wanting to do this?  Do you want to 
"translate" all of Python to French?  This is certainly not the way to 
go about it!  You're going to receive True and False from other 
functions/keywords whether you like it or not.  I would bet that "not 
Vrai" would be "False", for example.

-bob


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4