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


Groups > comp.lang.python > #74070

Re: How do you use `help` when write your code

References <CAJQX3DwnP24cnhofL2P90V3ux2oz2jT0p2KBDVOaUcWuteijbw@mail.gmail.com> <85a98mvvkj.fsf@benfinney.id.au>
Date 2014-07-07 12:58 +1000
Subject Re: How do you use `help` when write your code
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.11569.1404701890.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jul 7, 2014 at 10:53 AM, Ben Finney <ben@benfinney.id.au> wrote:
> There are two common cases where ‘help(foo)’ is unable to help:
>
> * If ‘foo’ is a function written without using keyword-only args, but
>   needing to have a bunch of keyword arguments, the signature will often
>   be the uninformative ‘foo(*args, **kwargs)’. A docstring is crucial
>   here, but it's too often wrong or absent.
>
>   I look forward to more and more functions migrating to use
>   keyword-only arguments for these cases, so the function signature can
>   become much more informative in ‘help’.

Most common cause of this problem is when a function ought to have
functools.wraps but didn't.

if DEBUG:
    debug = print
else:
    @functools.wraps(print)
    def debug(*a, **kw): pass

Without wraps(), the non-debug-mode version of debug() is completely unhelpful.

There's another issue with help(), and that's when it's used on a
large class - it's not that it's unhelpful, it's more that the useful
information gets lost in the spam of a pile of dunder functions. Check
out help(1) for instance.

ChrisA

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


Thread

Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 12:58 +1000

csiph-web