[Python-Dev] basenumber redux
Nick Coghlan
ncoghlan at gmail.com
Mon Jan 16 10:05:24 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!
I haven't really followed the earlier basenumber discussions (aside from the
sidetrack into the nature of mappings), but why would we want this ability as
a typecheck and not some form of interface check?
For example, what's wrong with "hasattr(x, __int__)"? That works for all the
builtin types, and, IMO, anyone defining a direct conversion to an integer for
a non-numeric type deserves whatever happens to them.
Something like:
def is_number(x):
return hasattr(x, '__int__')
def is_integer(x):
return x == int(x)
Requiring inheritance from "basenumber" in order to make something behave like
a real number seems antithetical to both duck-typing and the adaptation PEP.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list