[Python-Dev] basenumber redux

M.-A. Lemburg mal at egenix.com
Wed Jan 18 11:03:38 CET 2006


Alex Martelli wrote:
> 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 at all, basenumber would be an abstract class. However,
unlike for basestring, the interface (which methods it
supports, including operator methods) would not be well-
defined.

>> 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.

Hmm, I lost you there. If it's unsurprising that there's
no check for "a number", then why would you want a
basenumber ?

>> 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)):".

Why not use the functions I added to my previous mail ?

>> 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).

Again, why not use floatnumber() instead, which takes care
of all the details behind finding out whether an object
should be considered a number and even converts it to
a float for you ?

Why try to introduce a low-level feature when a higher
level solution is readily available and more usable.

You will rarely really care for the type of an object
if all you're interested in is the float value of an
object (or the integer value).

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 18 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the Python-Dev mailing list