[Python-checkins] r75051 - in python/branches/py3k: Lib/test/test_range.py Objects/rangeobject.c

Mark Dickinson dickinsm at gmail.com
Fri Sep 25 09:01:27 CEST 2009


On Fri, Sep 25, 2009 at 7:20 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
> On Thu, Sep 24, 2009 at 10:23 PM, Jim Jewett <jimjjewett at gmail.com> wrote:
>> Why not subclasses?
>> [snip long explanation that didn't really answer the question]

Two not-totally-out-of-this-world scenarios:
(1) Someone subclasses int to implement integer arithmetic
modulo 17; in doing so, he or she overrides __eq__ so that
a == b returns True iff a and b differ by a multiple of 17.
(2) Someone subclasses int to implement bounded integers;
the subclass is designed so that arithmetic operations that
would result in out-of-bound values raises OverflowError
instead. Then for this subclass it's quite possible that the
operations involved in the range optimization would produce
intermediate out-of-bound values, and hence raise OverflowError,
while the before-optimization range raised no exceptions.
I'm not claiming either of these is a sensible use of int
subclassing (they're probably not). In fact, I don't really
have much of an idea what *good* uses there are for
subclassing int.
Mark


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /