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


Groups > comp.lang.python > #43019 > unrolled thread

Re: __doc__ string for getset members

Started byArnaud Delobelle <arnodel@gmail.com>
First post2013-04-07 21:21 +0100
Last post2013-04-07 21:35 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: __doc__ string for getset members Arnaud Delobelle <arnodel@gmail.com> - 2013-04-07 21:21 +0100
    Re: __doc__ string for getset members Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-07 21:35 +0000

#43019 — Re: __doc__ string for getset members

FromArnaud Delobelle <arnodel@gmail.com>
Date2013-04-07 21:21 +0100
SubjectRe: __doc__ string for getset members
Message-ID<mailman.255.1365366070.3114.python-list@python.org>
On 7 April 2013 19:02, Nick Gnedin <ngnedin@gmail.com> wrote:
>
> Folks,
>
> I am writing an extension where I follow the guide on the web
> (http://docs.python.org/3.3/extending/newtypes.html#generic-attribute-management).
> I have an object declared,
>
> struct Object
> {
>     PyObject_HEAD
> };
>
> and a member set through tp_getset mechanism,
>
> PyGetSetDef ObjectGetSet[] =
> {
>     {"mem", (getter)MemGet, (setter)MemSet, "mem-doc-string", NULL},
>     {NULL}  /* Sentinel */
> };
>
> My question is - how do I access the doc string "mem-doc-string" supplied in
> the PyGetSetDef structure? If I type
>
> print(obj.mem.__doc__)
>
> then the __doc__ string for the result of a call to MemGet(...) is printed,
> not the doc string supplied in the PyGetSetDef structure.
>

That's not how Python works.  You won't be able to get the docstring
of a descriptor this way.  You need to do it from the class.  The
behaviour you observe is normal and cannot be overriden.

-- 
Arnaud

[toc] | [next] | [standalone]


#43023

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-04-07 21:35 +0000
Message-ID<5161e6b5$0$29995$c3e8da3$5496439d@news.astraweb.com>
In reply to#43019
On Sun, 07 Apr 2013 21:21:03 +0100, Arnaud Delobelle wrote:

> On 7 April 2013 19:02, Nick Gnedin <ngnedin@gmail.com> wrote:
[...]
>> My question is - how do I access the doc string "mem-doc-string"
>> supplied in the PyGetSetDef structure? If I type
>>
>> print(obj.mem.__doc__)
>>
>> then the __doc__ string for the result of a call to MemGet(...) is
>> printed, not the doc string supplied in the PyGetSetDef structure.
>>
>>
> That's not how Python works.  You won't be able to get the docstring of
> a descriptor this way.  You need to do it from the class.  The behaviour
> you observe is normal and cannot be overriden.


All very well and good, but how about putting Nick out of his misery and 
showing how to do it?


print(obj.__class__.mem.__doc__)


ought to work.



-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web