[New-bugs-announce] [issue7436] Define 'object with assignable attributes'
Terry J. Reedy
report at bugs.python.org
Fri Dec 4 22:23:01 CET 2009
New submission from Terry J. Reedy <tjreedy at udel.edu>:
On Python list, someone asked what guarantees that functions have and
will continue to have assignable attributes. I started to say 'the docs'
but failed to find anything specific in 7.6. Function definitions or
LibRef 5.12.3. Functions (all references to 3.1/2a docs).
5.3.1 Attribute references says "The primary must evaluate to an object
of a type that supports attribute references, which most objects do."
That is true for reading/getting but not for writing/setting.
6.2. Assignment statements says "If the target is an attribute
reference: The primary expression in the reference is evaluated. It
should yield an object with assignable attributes;" But which are those?
I propose to add a sentence like "Objects with assignable attributes
include modules, user-defined (Python-coded) functions and classes, and
instances of such classes."
If this leaves anything out, it can be expanded.
I tested and was somewhat surprised to modules based on C code (_socket,
_tkinter) allowed attribute setting. I use 'user'defined' because the
docs do in several places. I added 'Python-coded' because that is the
real relevant characteristic. C-coded user-defined functions in
user-written extension modules do not have settable attributes (I
presume), whereas imported Python-coded functions, in stdlib or 3-rd
party modules do. LibRef 5.12.3 "There are really two flavors of
function objects: built-in functions and user-defined functions." could
leave a reader wondering about imported functions.
A sentence could also be added there "User-defined (Python-coded)
functions have assignable attributes."
nosy: georg.brandl, tjreedy
title: Define 'object with assignable attributes'
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce