Style guide for subclassing built-in types?

Serge Orlov Serge.Orlov at gmail.com
Thu Feb 24 04:53:02 EST 2005


janeaustine50 at hotmail.com wrote:
> Thank you but your advice doesn't fit in my case since I want to keep
> the memory usage and the initial time minimum. iterable[::-1] would
> build another list and it would take big memory and time during
> reversing if iterable were huge. (and the "iterable" wouldn't be
> garbage-collected because I want to keep a reference to it)

You need to implement __iter__ method to pass your assert statement:
def __iter__(self):
    return reversed(self)

With regards to style guide:

1. write empty subclass
class rev_subclass(list):
    pass

2. print dir(rev_subclass) and write unit tests for every method. There
are 41 of them :) There is also __doc__ attribute you need to override.

3. Implement all the methods of rev_subclass to pass the tests.

  Serge.




More information about the Python-list mailing list