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


Groups > comp.lang.python > #27582

Re: Why does dynamic doc string do not work?

References <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> <CALwzidk+C_ipufecgmNJGr6f-6-B878R1ym8JkYzAErtWY-i8A@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-08-21 11:21 -0600
Subject Re: Why does dynamic doc string do not work?
Newsgroups comp.lang.python
Message-ID <mailman.3611.1345569735.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Aug 21, 2012 at 11:09 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka <miki.tebeka@gmail.com> wrote:
>> Greetings,
>>
>>>>> class A:
>> ...     '''a doc string'''
>> ...
>>>>> A.__doc__
>> 'a doc string'
>>>>> class B:
>> ...     '''a {} string'''.format('doc')
>> ...
>>>>> B.__doc__
>>>>>
>>
>> Is there's a reason for this?
>>
>> I know I can do:
>>>>> class B:
>> ...    __doc__ = '''a {} string'''.format('doc')
>>
>> And it'll work, but I wonder why the first B docstring is empty.
>
> The docstring is built at compile-time, not at run-time, so it must be
> a literal, not an arbitrary expression.

Also, if it did allow arbitrary expressions, then the syntax would be ambiguous.

def a():
    foo()
    do_stuff()

Is "foo()" intended to return a doc string?  If so, then it should be
called when the function object is built, not when the function is
called.  On the other hand, maybe it's intended to be part of the
function's code, in which case it should be called only when the
function itself is called.

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


Thread

Why does dynamic doc string do not work? Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-21 09:44 -0700
  Re: Why does dynamic doc string do not work? Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-21 11:09 -0600
  Re: Why does dynamic doc string do not work? MRAB <python@mrabarnett.plus.com> - 2012-08-21 18:16 +0100
  Re: Why does dynamic doc string do not work? Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-21 11:21 -0600
  Re: Why does dynamic doc string do not work? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-21 17:22 +0000
  Re: Why does dynamic doc string do not work? Dave Angel <d@davea.name> - 2012-08-21 13:30 -0400
    Re: Why does dynamic doc string do not work? Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-21 10:40 -0700
    Re: Why does dynamic doc string do not work? Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-21 10:40 -0700

csiph-web