Attribute inspection
Closed this issue · 8 comments
Hi. This is not an issue. Rather an improvement proposal. I thought that it may be useful if better_exceptions could show values of attributes accessed by period operator.
For instance, instead of:
Traceback (most recent call last):
File "foo.py", line 9, in <module>
print(123 / X.y)
└ <class '__main__.X'>
ZeroDivisionError: division by zero
we would get:
Traceback (most recent call last):
File "foo.py", line 9, in <module>
print(123 / X.y)
| └ 0
└ <class '__main__.X'>
ZeroDivisionError: division by zero
IssueHunt Summary
dtrckd has been rewarded.
Backers (Total: $40.00)
issuehunt ($40.00)
Submitted pull Requests
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
IssueHunt has been backed by the following sponsors. Become a sponsor
Interesting. I worry about the side effects of property access, however - since it's not just a lookup but potentially a function call, which means we'd also have to check for true property access beforehand.
But yeah, I think this could be done safely.
Good point.
Potential side effects of __getattr__
could be eliminated if we inspect only attributes from __dict__
of the object (and its class, and parent classes of this class). But __getattribute__
may still cause problems.
On the other hand, better_exceptions already calls __repr__
which theoretically also can have side effects. So general safety is violated anyway.
could be eliminated if we inspect only attributes from
__dict__
That's what I was thinking. inspect.getattr_static
would do nicely here.
On the other hand, better_exceptions already calls
__repr__
which theoretically also can have side effects. So general safety is violated anyway.
Yes but __repr__
having side effects isn't necessarily a good idea anyway, IMO. I don't really care about that.
inspect.getattr_static
- good finding. I agree regarding __repr__
.
Re repr()
I've created https://github.com/Qix-/better-exceptions/issues/85 - I think better-exceptions should not crash through it.
@issuehunt has funded $40.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
@Qix- has rewarded $28.00 to @dtrckd. See it on IssueHunt
- 💰 Total deposit: $40.00
- 🎉 Repository reward(20%): $8.00
- 🔧 Service fee(10%): $4.00