gh-153785: Generate AttributeError messages from context#153786
gh-153785: Generate AttributeError messages from context#153786johnslavik wants to merge 37 commits into
AttributeError messages from context#153786Conversation
This comment was marked as resolved.
This comment was marked as resolved.
AttributeError messages from contextAttributeError messages from context
Documentation build overview
5 files changed ·
|
| Py_END_CRITICAL_SECTION(); | ||
|
|
||
| if (!obj) { | ||
| return BaseException_str(op); |
There was a problem hiding this comment.
It might be worth a comment here that BaseException_str also locks and that's why this is outside of the lock.
There was a problem hiding this comment.
I tried to get Claude to look for whether similar situations have a comment convention, but couldn't find anything. I added a small "re-acquires lock" comment. Does it read useful?
There was a problem hiding this comment.
cc @kumaraditya303 as the person who made BaseException_str thread-safe
There was a problem hiding this comment.
Yeah, that looks good, it's enough of a breadcrumb for someone looking at it to not have to goto the other function.
I'm not sure how to create a nameless module at runtime
| result = PyUnicode_FromFormat("module has no attribute '%U'", name); | ||
| } | ||
| } else { | ||
| result = PyUnicode_FromFormat("'%.200s' object has no attribute '%U'", |
There was a problem hiding this comment.
Do we really want the whole qualname? Other AttributeError messages use %.200s or %.100s on tp_name.
There was a problem hiding this comment.
Please refrain from pushing so often intermediate commits. Only push when you are ready, preferably consolidated commit.
@vstinner, is there a format for short name?
There was a problem hiding this comment.
I can't find any myself looking at unicode_fromformat_arg.
This reverts commit 7378e30.
I think this is the best place to do this. We do the same trick in
KeyError.This also fixed issue #143811 that motivated the current one.
AttributeErrormessages from their context #153785