On Fri, Feb 11, 2022 at 5:39 AM Steven D'Aprano <st...@pearwood.info> wrote:

> On Thu, Feb 10, 2022 at 02:27:42PM -0800, Neil Girdhar wrote:
>
> > AttributeError: can't set attribute 'f'
> >
> > This can be a pain to debug when the property is buried in a base class.
>
> > Would it make sense to mention the reason why the attribute can't be
> set,
> > namely that it's on a property without a setter?
>
> I have no objection to changing the error message, I'm sure it's a small
> enough change that you should just open a ticket on b.p.o. for it. But I
> don't expect that it will be particularly useful either.
>
> If you can't set an attribute on an object, aren't there three obvious
> causes to check?
>

obvious?  See below.

>
> - the object has no __dict__, and so has no attributes at all;
>   e.g. trying to set an attribute on a float;
>
> - the object has slots, but 'f' is not one of them;
>
> - or 'f' is a property with no setter (or a setter that raises
>   AttributeError).
>
> Have I missed any common cases?
>

>>> Point = namedtuple('point', ('x', 'y'))
>>> p = Point(2, 3)
>>> p.x = 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute

Would this qualify as "obvious"?

<snip>

>
> Maybe reporting "can't set property 'f'" is good enough.
>
> +1
André

>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/Z2AWWETWB72CKARR4DAHB3A2LFRLQR7X/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/O3HVFO37C4F4IFVU2YIFORGANPRBOJTS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to