Edgewall Software

Changes between Initial Version and Version 1 of Ticket #9536, comment 32


Ignore:
Timestamp:
Jan 27, 2012, 6:27:33 PM (12 years ago)
Author:
Christian Boos

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #9536, comment 32

    initial v1  
    44If 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.
    55
    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()`).
     6And 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()`).
    77
    88Should 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.