Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
gvanrossum merged 11 commits intopython:mainfromGobot1234:better-error-for-no-dict
Jul 22, 2023

Conversation

@Gobot1234
Copy link
Contributor

@Gobot1234Gobot1234 commentedApr 4, 2023
edited by bedevere-bot
Loading

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.

@arhadthedevarhadthedev added the interpreter-core(Objects, Python, Grammar, and Parser dirs) labelApr 4, 2023
Comment on lines 1582 to 1583
"'%.100s' object has no attribute '%U' and no "
"__dict__ for setting new attributes",
Copy link
ContributorAuthor

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?

Copy link
Contributor

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.

@Gobot1234
Copy link
ContributorAuthor

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
Copy link
Contributor

thatbirdguythatuknownot commentedApr 4, 2023
edited
Loading

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.

@Gobot1234 The suggestion (Did you mean: 'foo'?) does not seem to be part of the error.

@ionite34
Copy link
Contributor

ionite34 commentedApr 4, 2023
edited
Loading

Should this perhaps check for__setattr__ overrides? There can be cases where the class has no__dict__ but some non slot attribute setting can still happen. In such a case this error might be misleading.

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

Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com>
@Gobot1234
Copy link
ContributorAuthor

@pablogsal since this is an error message change would you be willing to review?

@gvanrossumgvanrossum merged commitcdeb1a6 intopython:mainJul 22, 2023
@Gobot1234Gobot1234 deleted the better-error-for-no-dict branchJuly 22, 2023 12:43
cjwatson added a commit to cjwatson/testfixtures that referenced this pull requestNov 7, 2024
Start testing on 3.13, and fix a test for the change introduced inpython/cpython#103232.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@gvanrossumgvanrossumgvanrossum approved these changes

@ethanfurmanethanfurmanethanfurman approved these changes

+1 more reviewer

@thatbirdguythatuknownotthatbirdguythatuknownotthatbirdguythatuknownot left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@Gobot1234@thatbirdguythatuknownot@ionite34@gvanrossum@ethanfurman@arhadthedev@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp