classification
Title: Define 'object with assignable attributes'
Type: Stage:
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: daniel.urban, docs@python, eric.araujo, georg.brandl, terry.reedy
Priority: normal Keywords:

Created on 2009-12-04 21:22 by terry.reedy, last changed 2019-04-26 20:41 by BreamoreBoy.

Messages (3)
msg95972 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-12-04 21:22
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."
msg124656 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-26 01:50
We’d have to be careful to distinguish attributes defined to be not assignable and CPython implementation details.  In the absence of a definition in the doc, there is a chicken-and-egg problem, so I think a patch would have to be discussed on python-dev to get answers from the language designers.
msg227999 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-09-30 21:12
@Terry can you pick this one up?
History
Date User Action Args
2019-04-26 20:41:42BreamoreBoysetnosy: - BreamoreBoy
2014-09-30 21:12:54BreamoreBoysetnosy: + BreamoreBoy

messages: + msg227999
versions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2
2010-12-26 09:35:51daniel.urbansetnosy: + daniel.urban
2010-12-26 01:50:33eric.araujosetnosy: + eric.araujo

messages: + msg124656
versions: + Python 3.1, Python 2.7, Python 3.2
2010-08-04 21:27:37BreamoreBoysetassignee: georg.brandl -> docs@python

nosy: + docs@python
2009-12-04 21:22:59terry.reedycreate