[Python-Dev] n.numbits: method or property?

Mark Dickinson dickinsm at gmail.com
Wed Nov 12 19:19:57 CET 2008

[Antoine Pitrou]
> No, but Python is duck-typed and alternate integer classes could adopt such an
> implementation while trying to respect the Python-level long API.

Good point.  That makes me feel a little uneasy about adding numbits
at all.  Though I guess there are other parts of Python's integer API that are
inherently linked to a binary representation, namely, the bit operations and
shifts.  And there'd be no *requirement* for alternative integer types to
implement numbits (it wouldn't be part of the Integral ABC, for example).

> What do you call Decimal?  ;-)

Um.  A stdlib module?  I guess I should have said that I can't see Python
adopting a nonbinary implementation for the 'int/long' types.

It *is* fun to dream about, though: there are some definite advantages
to an internal decimal representation---notably, faster str <-> int
conversion.  And it turns out that overall performance doesn't suffer:
I've coded up a Python extension module that implements decimal
integers (stored internally in base 10**9) whose performance handily
beats that of the current binary int/long.


More information about the Python-Dev mailing list