"help( pi )"

Cameron Simpson cs at cskk.id.au
Wed Nov 22 03:20:39 EST 2017


On 22Nov2017 18:47, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>Cameron Simpson wrote:
>>one could change  implementations such that applying a docstring to 
>>an object _removed_ it from  the magic-shared-singleton pool,
>
>That's not sufficient, though. Consider:
>
>   BUFFER_SIZE = 256
>   BUFFER_SIZE.__doc__ = "Size of the buffer"
>
>   TWO_TO_THE_EIGHT = 256
>   TWO_TO_THE_EIGHT.__doc__ = "My favourite power of two"
>
>Before the code is even run, the compiler may have merged the
>two occurences of the integer literal 256 into one entry in
>co_consts. By the time the docstrings are assigned, it's too
>late to decide that they really needed to be different objects.
>
>So, an int with a docstring needs to be explicitly created as
>a separate object to begin with, one way or another.

Ah.

Even without that it felt a little racy to me anyway.

Cheers,
Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list