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

bpo-43857: Improve the AttributeError message when deleting a missing attribute#25424

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
JelleZijlstra merged 13 commits intopython:mainfromgeryogam:patch-24
May 5, 2022

Conversation

geryogam
Copy link
Contributor

@geryogamgeryogam commentedApr 15, 2021
edited by JelleZijlstra
Loading

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelJun 3, 2021
Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I agree with this idea. Could you add a NEWS entry and a unit test that exercises this message?

(I promise I'm not stalking you, I just opened page 24 of the open PRs and found this one :) .)

@geryogamgeryogam changed the titlebpo-43857: Fix the AttributeError message for deletion of a missing attributebpo-43857: Improve the AttributeError message when deleting a missing attributeMay 4, 2022
@JelleZijlstraJelleZijlstra self-assigned thisMay 4, 2022
@geryogam
Copy link
ContributorAuthor

Thanks@JelleZijlstra, but please don’t merge right now as some tests are failing. I am going to work on it in the next few hours. I’ll let you know when it works.

JelleZijlstra reacted with thumbs up emoji

@geryogam
Copy link
ContributorAuthor

geryogam commentedMay 4, 2022
edited
Loading

Not only objects but alsotype objects have inconsistentAttributeError messages between missing attribute retrieval and deletion:

$python3Python3.9.12 (main,Mar262022,15:52:10) [Clang13.0.0 (clang-1300.0.29.30)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>classA:pass...>>>A.xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:typeobject'A'hasnoattribute'x'>>>delA.xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:x>>>A().xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:'A'objecthasnoattribute'x'>>>delA().xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:x

Compare that with PyPy for which the messages are consistent (well almost,'type' object has no attribute 'x' should betype object 'A' has no attribute 'x' fordel A.x):

$pypy3Python3.7.13 (7e0ae751533460d5f89f3ac48ce366d8642d1db5,Apr262022,09:31:20)[PyPy7.3.9withGCCAppleLLVM13.0.0 (clang-1300.0.29.30)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>>classA:pass>>>>>>>>A.xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:typeobject'A'hasnoattribute'x'>>>>delA.xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:'type'objecthasnoattribute'x'>>>>A().xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:'A'objecthasnoattribute'x'>>>>delA().xTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>AttributeError:'A'objecthasnoattribute'x'

Following@markshannon’s PR#28802 for Python 3.11, the message fix ofthis line in Objects/object.c provided at the early stage of this PR no longer works for objects but only fortype objects:

if (res<0&&PyErr_ExceptionMatches(PyExc_KeyError))-PyErr_SetObject(PyExc_AttributeError,name);+PyErr_Format(PyExc_AttributeError,+"'%.100s' object has no attribute '%U'",+tp->tp_name,name);

To fix the message for objects, we should also updatethis line in Objects/dictobject.c:

-PyErr_SetObject(PyExc_AttributeError,name);+PyErr_Format(PyExc_AttributeError,+"'%.100s' object has no attribute '%U'",+Py_TYPE(obj)->tp_name,name);

That way we get the same messages as in PyPy.

Finally to solve the last message inconsistency ('type' object has no attribute 'x' should betype object 'A' has no attribute 'x' fordel A.x), I replaced the last fix in Objects/object.c with this fix:

-if (res<0&&PyErr_ExceptionMatches(PyExc_KeyError))-PyErr_SetObject(PyExc_AttributeError,name);+if (res<0&&PyErr_ExceptionMatches(PyExc_KeyError)) {+if (PyType_IsSubtype(tp,&PyType_Type)) {+PyErr_Format(PyExc_AttributeError,+"type object '%.50s' has no attribute '%U'",+                          ((PyTypeObject*)obj)->tp_name,name);+         }+else {+PyErr_Format(PyExc_AttributeError,+"'%.100s' object has no attribute '%U'",+tp->tp_name,name);+         }+     }

@geryogam
Copy link
ContributorAuthor

@JelleZijlstra Done, all tests are passing. The PR is ready.

@JelleZijlstraJelleZijlstra merged commita95138b intopython:mainMay 5, 2022
@geryogamgeryogam deleted the patch-24 branchMay 5, 2022 14:04
@geryogam
Copy link
ContributorAuthor

geryogam commentedMay 5, 2022
edited
Loading

Thanks again@JelleZijlstra!

(I promise I'm not stalking you, I just opened page 24 of the open PRs and found this one :) .)

No worries. And even if you were stalking my PRs I would not complain, quite the opposite =)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

@methanemethaneAwaiting requested review from methanemethane is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

@JelleZijlstraJelleZijlstra

Labels
staleStale PR or inactive for long period of time.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@geryogam@JelleZijlstra@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp