Message95972
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." |
|
Date |
User |
Action |
Args |
2009-12-04 21:23:01 | terry.reedy | set | recipients:
+ terry.reedy, georg.brandl |
2009-12-04 21:23:01 | terry.reedy | set | messageid: <1259961781.03.0.33355289278.issue7436@psf.upfronthosting.co.za> |
2009-12-04 21:22:59 | terry.reedy | link | issue7436 messages |
2009-12-04 21:22:58 | terry.reedy | create | |
|