Documenting builtin methods

Mark Janssen dreamingforward at gmail.com
Wed Jul 10 23:29:14 EDT 2013


> I have this innocent and simple code:
>
> from collections import deque
> exhaust_iter = deque(maxlen=0).extend
> exhaust_iter.__doc__ = "Exhaust an iterator efficiently without
> caching any of its yielded values."
>
> Obviously it does not work. Is there a way to get it to work simply
> and without creating a new scope (which would be a rather inefficient
> a way to set documentation, and would hamper introspection)?
>
> How about dropping the "simply" requirement?

I think the canonical way to specialize a class (even if it's only
docstrings or method re-names) is to extend it with a new class.

markj



More information about the Python-list mailing list