This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients georg.brandl, terry.reedy
Date 2009-12-04.21:22:58
SpamBayes Score 4.976075e-12
Marked as misclassified No
Message-id <1259961781.03.0.33355289278.issue7436@psf.upfronthosting.co.za>
In-reply-to
Content
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."
History
Date User Action Args
2009-12-04 21:23:01terry.reedysetrecipients: + terry.reedy, georg.brandl
2009-12-04 21:23:01terry.reedysetmessageid: <1259961781.03.0.33355289278.issue7436@psf.upfronthosting.co.za>
2009-12-04 21:22:59terry.reedylinkissue7436 messages
2009-12-04 21:22:58terry.reedycreate