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?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; '21,': 0.07; 'called.': 0.09; 'received:mail-lpp01m010-f46.google.com': 0.09; 'subject:Why': 0.09; 'subject:string': 0.09; 'def': 0.10; 'subject:not': 0.11; 'aug': 0.13; '11:09': 0.16; 'a():': 0.16; 'docstring': 0.16; 'empty.': 0.16; 'expression.': 0.16; 'expressions,': 0.16; 'foo()': 0.16; "function's": 0.16; 'literal,': 0.16; 'subject:doc': 0.16; 'wrote:': 0.17; 'code,': 0.18; 'doc': 0.22; 'work,': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'class': 0.29; 'maybe': 0.29; 'received:209.85.215.46': 0.30; 'function': 0.30; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'so,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'itself': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'built,': 0.84; 'do:': 0.91; 'hand,': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=3jv61LV3Cs1lgrwIHNtsCbq1CCw5IheM2u/64V8FBvM=; b=dzuGPwGzNKkOiW9+jefecrU0Mcqx1fSg6lgoJ1nTLeeSIDo3jWKpI8h3/kzMQMr0c9 lp6n/mqyhZkVVlWS+JMKUkNuEiy9tb4lWRlrBPmlELx4h7nxGUJsRwkFXg9FOcUqPtCQ mMbeH0N/ECuVD6mZXXQe8cfz6Vxe5gLgFfLHKCSMAuDQ6hanXjM6n+/7h2gdkhi+UQiQ 42DyEtqplXidhH/fxB/E3y2r45LDwbnM0o6WaE/fo3lWMhXwh81rWIB2VsVhbvHPUojH vTqlfCa2hxeL+/EQpTb2cpZSZmAZyzhVtDbx3795Qv8s3w3Mnct9b24tetVNKyWcesaD Ehlw==
MIME-Version 1.0
In-Reply-To <CALwzidk+C_ipufecgmNJGr6f-6-B878R1ym8JkYzAErtWY-i8A@mail.gmail.com>
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 Tue, 21 Aug 2012 11:21:10 -0600
Subject Re: Why does dynamic doc string do not work?
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3611.1345569735.4697.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345569735 news.xs4all.nl 6977 [2001:888:2000:d::a6]:49688
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27582

Show key headers only | 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