Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-96663: Add a better error message for __dict__-less classes setattr#103232
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Objects/object.c Outdated
| "'%.100s' object has no attribute '%U' and no " | ||
| "__dict__ for setting new attributes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I can't find the tests for this bit of code, are there any?
thatbirdguythatuknownot left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There's an example that raises the error message when a__dict__ is available, so there has to be a check in the second path.
Uh oh!
There was an error while loading.Please reload this page.
Gobot1234 commentedApr 4, 2023
I'm not entirely sure why the tests are failing >>>classB:... y=0...__slots__= ('z','foo')... >>> B().fod=1Traceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'B' object has no attribute 'fod' and no __dict__ for setting new attributes. Did you mean: 'foo'? AFAICT this should be the error that you get? Unless it's failing due to not being printed. |
thatbirdguythatuknownot commentedApr 4, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@Gobot1234 The suggestion ( |
ionite34 commentedApr 4, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Should this perhaps check for classFoo:__slots__= ("x","y")def__setattr__(self,name,val):ifname=="all":self.x=valself.y=valelse:super().__setattr__(name,val)f=Foo()f.all=5 |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Gobot1234 commentedApr 6, 2023
@pablogsal since this is an error message change would you be willing to review? |
Uh oh!
There was an error while loading.Please reload this page.
Start testing on 3.13, and fix a test for the change introduced inpython/cpython#103232.
Uh oh!
There was an error while loading.Please reload this page.
I think this addresses all the issues I have with the current message. Thanks to Eryk for the pointer as to where I should be editing.