[Python-Dev] basenumber redux
"Martin v. Löwis"
martin at v.loewis.de
Mon Jan 16 07:39:41 CET 2006
Alex Martelli wrote:
> I'll be happy to draft a PEP if needed (and just as happy to
> eventually provide an implementation patch if the PEP's accepted),
> but wanted to doublecheck on the general issue first!
Please do so. I've browsed somewhat through past discussions,
but wasn't able to find a proposed specification of basenumber.
Also, I only found half of a rationale for it: it is meant to
be used along with isinstance, but I couldn't find out why
you wanted to do that. In
http://mail.python.org/pipermail/python-dev/2003-November/039916.html
you explain that you wanted to multiply all items of self with
other if other is a number; why couldn't this be written as
def __mul__(self, other):
try:
return self.__class__([ x*other for x in self.items ])
except TypeError:
# various other multiplication cases
You give performance as the rationale; this is unconvincing as
it would rather indicate that performance of exceptions should
be improved (also, I think it is unpythonic to change the
language for performance reasons, except in really common
cases).
Also, in that example, I wonder if the use of multiplication
is flawed. If you have so many multiplication cases, perhaps
you abuse the notion of multiplication? Users will need to
understand the different cases, as well, and they will be
surprised when it works in one case, but not in a (seemingly
similar) othercase.
Regards,
Martin
More information about the Python-Dev
mailing list