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: Please consider mentioning property without setter when an attribute can't be set
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Alex-Blade, Dennis Sweeney, NeilGirdhar, christian.heimes, rhettinger, xtreak
Priority: normal Keywords: patch

Created on 2022-02-12 11:15 by NeilGirdhar, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31311 merged Alex-Blade, 2022-02-13 02:43
PR 31389 merged christian.heimes, 2022-02-17 15:49
PR 31427 merged Dennis Sweeney, 2022-02-19 05:36
Messages (9)
msg413122 - (view) Author: Neil Girdhar (NeilGirdhar) * Date: 2022-02-12 11:15
class C:
    @property
    def f(self) -> int:
        return 2

class D(C):
    pass

D().f = 2

Gives:

Traceback (most recent call last):
  File "/home/neil/src/cmm/a.py", line 10, in <module>
    D().f = 2
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?
msg413152 - (view) Author: Alexander (Alex-Blade) * Date: 2022-02-13 01:37
Indeed, the error message does not help to identify the problem. Moreover, it collides with similar errors in namedtuple and DynamicClassAttribute which may lead to even more confusion.

I made a draft patch that could help with it (https://github.com/Alex-Blade/cpython/commit/06df3a72dfe462c8fe4eac60dce0ef059b1738f8), but I have a concern related to backwards compatibility (that's why no PR). I don't really understand if according to PEP 387 a change in an exception message should be considered compatibility breaking?
msg413153 - (view) Author: Neil Girdhar (NeilGirdhar) * Date: 2022-02-13 01:50
Thank you, this would have saved me a lot of time!

On Sat, Feb 12, 2022 at 8:37 PM Alexander <report@bugs.python.org> wrote:

>
> Alexander <lakeevveekal@gmail.com> added the comment:
>
> Indeed, the error message does not help to identify the problem. Moreover,
> it collides with similar errors in namedtuple and DynamicClassAttribute
> which may lead to even more confusion.
>
> I made a draft patch that could help with it (
> https://github.com/Alex-Blade/cpython/commit/06df3a72dfe462c8fe4eac60dce0ef059b1738f8),
> but I have a concern related to backwards compatibility (that's why no PR).
> I don't really understand if according to PEP 387 a change in an exception
> message should be considered compatibility breaking?
>
> ----------
> nosy: +Alex-Blade
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue46730>
> _______________________________________
>
msg413154 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-02-13 01:58
Go ahead and open a PR -- it makes it easier to discuss particular changes.

Regarding backwards-compatibility, error messages improvements are fair game for Python 3.11, we just shouldn't backport them to earlier versions.

We can also consider including the type of the relevant object in the error messages.
msg413161 - (view) Author: Alexander (Alex-Blade) * Date: 2022-02-13 02:50
Added the PR. (I have signed the CLA, just haven't got the response yet, doesn't affect the discussion I guess)
msg413318 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-02-16 07:07
New changeset 0cb765b2cec9b020224af016a83bf35c45b71932 by Alex-Blade in branch 'main':
bpo-46730: Add more info to @property AttributeError messages (GH-31311)
https://github.com/python/cpython/commit/0cb765b2cec9b020224af016a83bf35c45b71932
msg413319 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-02-16 07:16
Thanks for the PR!
msg413446 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-02-17 19:27
New changeset 9e06d03672547041239812efe4901c06da6cbd2f by Christian Heimes in branch 'main':
bpo-46730: Fix refleak and tighten NULL checks (GH-31389)
https://github.com/python/cpython/commit/9e06d03672547041239812efe4901c06da6cbd2f
msg413532 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2022-02-19 05:28
The test introduces a deprecation warning. It might be fixed by using raw string like the msg_format used in other test.


./python -Wall -m py_compile Lib/test/test_property.py
Lib/test/test_property.py:345: DeprecationWarning: invalid escape sequence '\.'
  msg_format = "^property of 'PropertyUnreachableAttributeNoName\.cls' object {}$"
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90886
2022-02-19 05:36:47Dennis Sweeneysetpull_requests: + pull_request29562
2022-02-19 05:28:28xtreaksetnosy: + xtreak
messages: + msg413532
2022-02-17 19:27:53Dennis Sweeneysetmessages: + msg413446
2022-02-17 15:49:48christian.heimessetnosy: + christian.heimes

pull_requests: + pull_request29534
2022-02-16 07:16:46Dennis Sweeneysetstatus: open -> closed
resolution: fixed
messages: + msg413319

stage: patch review -> resolved
2022-02-16 07:07:43Dennis Sweeneysetmessages: + msg413318
2022-02-13 02:53:53xtreaksetnosy: + rhettinger
2022-02-13 02:50:16Alex-Bladesetmessages: + msg413161
2022-02-13 02:43:12Alex-Bladesetkeywords: + patch
stage: patch review
pull_requests: + pull_request29472
2022-02-13 01:58:28Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg413154
2022-02-13 01:50:38NeilGirdharsetmessages: + msg413153
2022-02-13 01:37:19Alex-Bladesetnosy: + Alex-Blade
messages: + msg413152
2022-02-12 11:15:48NeilGirdharcreate