[PEP 224] Attribute Docstrings

Frank Niessink frankn=nuws at cs.vu.nl
Sun Aug 27 17:18:39 EDT 2000


Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> Frank Niessink <frankn=nuws at cs.vu.nl> (FN) writes:

> FN> It is my understanding that in the long run, every object in Python
> FN> will become a 'real' object. If that is the case, wouldn't the naming
> FN> scheme <attributename>.__doc__ be a better one?

> FN> So if:

> FN> class C:
> FN>   a = 1
> FN>   """Description of a."""

> FN> then:

> FN> C.a.__doc__ == "Description of a."

> No, that wouldn't work, as C.a == 1, so C.a.__doc__ == 1.__doc__.
> But you are not interested in the meaning of 1, but in the attribute a of
> class C, no matter what its current value is.

I'm not too familiar with the internals of Python, but isn't the 
reason you're right caused by the fact that all integers are 'interned'?

If they weren't (or at least not if a docstring is present) my proposal
would not be impossible, right?

In that case, this would be possible:

>>> players = 1
>>> players.__doc__ = 'players is the number of human players'
>>> comp = 1
>>> comp.__doc__ = 'comp is the number of computer players'
>>> players == comp
>>> 1
>>> players is comp
>>> 0           # I would think

Cheers, Frank
-- 
"Look," said Zaphod, "I'm up to here with cool, OK? I'm so amazingly cool you
could keep a side of meat inside me for a month."
	-- Douglas Adams, 'The Restaurant at the End of the Universe'



More information about the Python-list mailing list