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.

classification
Title: setattr on a property gives a very unhelpful exception
Type: behavior Stage: resolved
Components: Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: setattr a read-only property; the AttributeError should show the attribute that failed
View: 27794
Assigned To: Nosy List: diekhans, r.david.murray, rhettinger
Priority: normal Keywords:

Created on 2017-11-09 04:11 by diekhans, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg305933 - (view) Author: Mark Diekhans (diekhans) Date: 2017-11-09 04:11
done a setattr on a property gives a very unhelpful error message

   AttributeError: can't set attribute

it neither indicates the name of the attribute that failed or the cause.

an error such as "can't set property attribute: the_attr_name"

would be far more helpful.
msg305934 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-11-09 04:49
Usually, all the necessary information is present in the previous line of the traceback:

    >>> a.volume = 10
    Traceback (most recent call last):
      File "<pyshell#6>", line 1, in <module>
        a.volume = 10
    AttributeError: can't set attribute

I don't seem to recall anyone else having problems with this error message.
msg305935 - (view) Author: Mark Diekhans (diekhans) Date: 2017-11-09 04:56
The trackback is not helpful if the attribute name is in a
variable.  It also doesn't explain why the error occurred.

While I would not rate this as a high priority, I don't see an
argument for having uninformative error messages.

Raymond Hettinger <report@bugs.python.org> writes:
> 
> Raymond Hettinger <raymond.hettinger@gmail.com> added the comment:
> 
> Usually, all the necessary information is present in the previous line of the traceback:
> 
>     >>> a.volume = 10
>     Traceback (most recent call last):
>       File "<pyshell#6>", line 1, in <module>
>         a.volume = 10
>     AttributeError: can't set attribute
> 
> I don't seem to recall anyone else having problems with this error message.
> 
> ----------
> nosy: +rhettinger
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue31989>
> _______________________________________
msg305961 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-11-09 14:20
This is a duplicate of #27794.
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76170
2017-11-09 14:20:41r.david.murraysetstatus: open -> closed

superseder: setattr a read-only property; the AttributeError should show the attribute that failed
versions: + Python 3.8, - Python 2.7, Python 3.4, Python 3.5, Python 3.6
nosy: + r.david.murray

messages: + msg305961
resolution: duplicate
stage: resolved
2017-11-09 04:56:24diekhanssetmessages: + msg305935
2017-11-09 04:49:15rhettingersetnosy: + rhettinger
messages: + msg305934
2017-11-09 04:11:26diekhanscreate