[Python-ideas] range

Nick Coghlan ncoghlan at gmail.com
Sat Feb 23 12:11:11 CET 2013


On Sat, Feb 23, 2013 at 7:21 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 2/22/2013 1:43 PM, Antoine Pitrou wrote:
>>
>> On Fri, 22 Feb 2013 17:40:29 +0000 (UTC)
>> Wolfgang Maier
>> <wolfgang.maier at biologie.uni-freiburg.de>
>
>
>>> Any plans to make range a valid base class to build upon in future
>>> releases?
>>
>>
>> I suppose it wouldn't very difficult to make range subclassable.
>> You can try writing a patch if you want:
>> http://docs.python.org/devguide/
>
>
> I was just about to suggest that making range subclassable would be an
> alternative to extending the current class. As far as I know, there is no
> principled reason why not, unlike Nonetype and bool.

I wasn't even aware you *couldn't* subclass it (I'd never tried). As
far as I am aware, that's just a quirk inherited from the old xrange
implementation rather than a deliberate design decision.

On the other hand, I suspect for many cases involving more advanced
range variants, containment would be a better option than inheritance,
particular if you want to implement a type that can't be reliably
described through a (start, stop, step) triple.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list