Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50415

Re: Documenting builtin methods

From alex23 <wuwei23@gmail.com>
Newsgroups comp.lang.python
Subject Re: Documenting builtin methods
Date 2013-07-11 15:35 +1000
Organization A noiseless patient Spider
Message-ID <krlft3$c66$1@dont-email.me> (permalink)
References <mailman.4558.1373512579.3114.python-list@python.org>

Show all headers | View raw


On 11/07/2013 1:15 PM, Joshua Landau wrote:
> 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)?

I would just go with the most obvious approach:

     def exhaust_iter(iter):
         """
         Exhaust an iterator efficiently without caching
         any of its yielded values
         """
         deque(maxlen=0).extend(iter)

It's not going to be that inefficient unless you're calling it in a long 
inner loop.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Documenting builtin methods Joshua Landau <joshua@landau.ws> - 2013-07-11 04:15 +0100
  Re: Documenting builtin methods alex23 <wuwei23@gmail.com> - 2013-07-11 15:35 +1000
  Re: Documenting builtin methods Steven D'Aprano <steve@pearwood.info> - 2013-07-11 06:06 +0000
    Re: Documenting builtin methods Chris Angelico <rosuav@gmail.com> - 2013-07-11 17:06 +1000
      Re: Documenting builtin methods Steven D'Aprano <steve@pearwood.info> - 2013-07-11 07:15 +0000
        Re: Documenting builtin methods Chris Angelico <rosuav@gmail.com> - 2013-07-11 17:23 +1000
    Re: Documenting builtin methods Joshua Landau <joshua@landau.ws> - 2013-07-12 00:11 +0100
      Re: Documenting builtin methods alex23 <wuwei23@gmail.com> - 2013-07-12 13:43 +1000
        Re: Documenting builtin methods Joshua Landau <joshua@landau.ws> - 2013-07-12 08:09 +0100

csiph-web