Documenting builtin methods

alex23 wuwei23 at
Fri Jul 12 05:43:05 CEST 2013

On 12/07/2013 9:11 AM, Joshua Landau wrote:
> I also feel that:
> def factory():
>      eatit = deque(maxlen=0).extend
>      def exhaust_iter(it):
>          """Doc string goes here"""
>          eatit(it)
>      return exhaust_iter
> exhaust_it = factory()
> del factory
> is a very unobvious way to change a docstring and hides what I'm doing
> very effectively.

My last post seems to have been eaten by either Thunderbird or the 
EternalSeptember servers, but it contained an erroneous claim that the 
straight function version performed as well as the factory one. However, 
in the interim a co-worker has come up with a slightly faster variant:

from functools import partial
from collections import deque

class exhaust_it(partial):
     """custom doc string"""

exhaust_it = exhaust_it(deque(maxlen=0).extend)

Shadowing the class name with the partial instance will ensure it has 
the same name when accessed via help(), and it's a simple way to avoid 
needing to clean up the namespace, as well.

More information about the Python-list mailing list