-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please consider mentioning property without setter when an attribute can't be set #90886
Comments
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? |
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 (Alex-Blade@06df3a7), 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? |
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:
|
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. |
Added the PR. (I have signed the CLA, just haven't got the response yet, doesn't affect the discussion I guess) |
Thanks for the PR! |
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 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: