New submission from Terry J. Reedy <tjre...@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." ---------- assignee: georg.brandl components: Documentation messages: 95972 nosy: georg.brandl, tjreedy severity: normal status: open title: Define 'object with assignable attributes' _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7436> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com