Re: Catching AttributeError exceptions in widget media

2014-09-05 Thread Michael Jones
Thanks for the clarification guys. That is truly horrific :) Sorry not to have tested my suggestion first. Michael On Thursday, September 4, 2014 5:20:18 PM UTC+1, Zachary McCord wrote: > > I simply didn't believe it at first, but sure enough, in python 2.7: > > >>> class Bomb(object): > ...

Re: Catching AttributeError exceptions in widget media

2014-09-04 Thread Zachary McCord
I simply didn't believe it at first, but sure enough, in python 2.7: >>> class Bomb(object): ... def __getattr__(self, id): ... assert False ... >>> bomb = Bomb() >>> bomb.foo Traceback (most recent call last): File "", line 1, in File "", line 3, in __getattr__ Assertion

Re: Catching AttributeError exceptions in widget media

2014-09-04 Thread Collin Anderson
believe it or not, hasattr is the same as: try: getattr(obj, name) return True except: # yikes! naked except! return False https://docs.python.org/2/library/functions.html#hasattr So, excepting AttributeError will at least narrow down the error slightly, rather than hasattr accepting

Re: Catching AttributeError exceptions in widget media

2014-09-04 Thread Michael Jones
Hi, Thanks for the reply, but I'm not sure I follow. I was hoping that the following might work: if hasattr(sup_cls, 'media'): base = sup_cls.media else: base = Media() Would that swallow additional exceptions? Cheers, Michael On Wednesday, September 3, 2014 10:45:22

Re: Catching AttributeError exceptions in widget media

2014-09-03 Thread Collin Anderson
unfortunately hasattr eats even more exceptions than AttributeError. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. T

Catching AttributeError exceptions in widget media

2014-09-03 Thread Michael Jones
Hi, I love Django, it has been enormously useful to a new comer to web dev like me. One minor issue I've just had is that I've struggled to figure out an issue with my code because an AttributeError I was generating in my media property on my custom widget was being silently swallowed by: