[Python-Dev] basenumber redux

Alex Martelli aleaxit at gmail.com
Tue Jan 17 23:53:51 CET 2006


On 1/17/06, M.-A. Lemburg <mal at egenix.com> wrote:
> Alex, I think you're missing a point here: what you are looking
> for is an interface, not a base class - simply because the

I expect numbers to support arithmetic operators, &c -- no need for
basenumber to "spell this out", i.e., "be an itnerface".

> If you look at the Python C API, you'll find that "a number"
> is actually never tested.

There being no way to generically test for "a number", that's unsurprising.

> The tests always ask for either
> integers or floats.

But this doesn't apply to the Python Standard Library, for example see
line 1348 of imaplib.py: "if isinstance(date_time, (int, float)):".

> The addition of a basenumber base class won't make these any
> simpler.

Being able to change imaplib to use basenumber instead of (int, float)
won't make it SIMPLER, but it will surely make it BETTER -- why should
a long be rejected, or a Decimal,
for that matter?  Similarly, on line 1352 it should use the existing
basestring, though it now uses str (this function IS weird -- if it
finds date_time to be of an unknown TYPE it raises a *ValueError*
rather than a *TypeError* -- ah well).


Alex


More information about the Python-Dev mailing list