Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dashscope/api_entities/dashscope_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def setattr(self, attr, value):
return super().__setitem__(attr, value)

def __getattr__(self, attr):
return self[attr]
try:
return self[attr]
except KeyError:
raise AttributeError(attr) from None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While raising AttributeError correctly fixes the reported issue, the error message could be improved to follow standard Python conventions. Currently, it only provides the attribute name, which results in a terse error like AttributeError: missing_attr. A more descriptive message including the class name (e.g., AttributeError: 'DashScopeAPIResponse' object has no attribute 'missing_attr') would be more helpful for debugging and consistent with built-in Python behavior.

Suggested change
raise AttributeError(attr) from None
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{attr}'") from None


def __setattr__(self, attr, value):
self[attr] = value
Expand Down