PEP 285: Adding a bool type

Martin v. Loewis martin at v.loewis.de
Mon Apr 1 03:20:32 EST 2002


Kirill Simonov <kirill_simonov at mail.ru> writes:

> * Martin v. Loewis <martin at v.loewis.de>:
> > Can you show examples of (real!) code that will break? Preferably code
> > you've written yourself.
> 
> The changes will break the code like this:
> 
> if type(arg) == type(''):
>     ...
> elif type(arg) == type(0):
>     ...
> 
> You can find such code even in the standard library.

As a general example, I agree. I even know a place in PyXML that I
will need to change: For the better, it turns out, since it dispatches
by the type, but needed a special TruthValue class to support the
notion of boolean values in the underlying XML DTD.

I'm asking about *specific* code that will need to change. There are 8
occurrences of "type(0)" in the standard library. Of those *none* will
break. 

The occurrence in RExec could stand some improvement: either support
for the old signature could be entirely removed, or the type check
should be changed to an isinstance(args[-1],int) check. In the current
code, breakage would only occur if somebody passed a bool as the
verbose argument. Without seeing an application, this is hard to
establish; all usages within Python itself either let the paramater
default, or pass an integer (rexec.test does that).

So it is not clear that anything in the standard library will break.

Regards,
Martin



More information about the Python-list mailing list