On 09/10/2012 10:12, Chris McDonough wrote:
On Tue, 2012-10-09 at 10:04 +0930, Chris Withers wrote:
On 09/10/2012 09:57, Chris McDonough wrote:
No.  Both hasattr and getattr hide AttributeError.

I knew about hasattr, but how does getattr hide AttributeError?

What you want is for "real" AttributeErrors to bubble up through the
getattr but they don't.  For example, if you do this:

Yeah, that is annoying..

If it were me, I'd do this:

# nb: does not subclass AttributeError
class InnerAttributeError(Exception):
    pass

class Foo(object):
     @property
     def __acl__(self):
         try:
             ...
             raise AttributeError('abc')
         except AttributeError as e:
             raise InnerAttributeError(e)

If I used it more than once, I'd probably turn it into a decorator:

class Foo(object):
     @property
     @raise_inner_attribute_error
     def __acl__(self):
         ...
         raise AttributeError('abc')

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to