Changes between Initial Version and Version 1 of Ticket #9536, comment 32
- Timestamp:
- Jan 27, 2012, 6:27:33 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #9536, comment 32
initial v1 4 4 If we do, we should decide on a case-by-case basis what the replacement should be. Sometimes the `hasattr()` call is even redundant, as it is followed by a `getattr()`, sometimes it can be replaced by a `try: except AttributeError:` block, sometimes a default value could be set at the class level. 5 5 6 And sometimes the `hasattr()` call is needed. In that case, I would replace the call with ` hasattr(a, b, noattr) is not noattr` where `noattr` is a marker object (which could simply be defined as `noattr = object()`).6 And sometimes the `hasattr()` call is needed. In that case, I would replace the call with `getattr(a, b, noattr) is not noattr` where `noattr` is a marker object (which could simply be defined as `noattr = object()`). 7 7 8 8 Should we do the change? The buggy behavior of swallowing all exceptions is only an issue when `hasattr()` is called on an object with a custom `__getattr__()` method. So we could probably leave most calls alone, and just fix the ones that are really affected.