Logged In: YES
user_id=6380
There seems to be a problem with this patch. It introduces
__getattr__, __hasattr__ and __delattr__ methods, which
attempt to delegate attributes to the self.tk object if they
aren't defined on self. This is fine for __getattr__.
__hasattr__ is based on a misunderstanding; there is no
special __hasattr__ method. Butthe real problem is
__delattr__ -- remember the asymmetry between __getattr__
and __setattr__? __getattr__ is only called as a fall-back
(when the attribute isn't found using the normal attribute
search), but __setattr__, if defined, is *always* called.
Well, __delattr__ behaves the same way as __setattr__. The
end result is that if someone sets a private attribute on a
Tk() instance, it can be set (because __setattr__ is not
defined) cannot be deleted (because __delattr__ is).
Why do I care? It breaks Tkdnd! Tkdnd stores a private
attribute (__dnd) on the Tk() object to indicate that it is
active, and deletes it to indicate that it is no longer active.
The fix is easy from my perspective: just get rid of the
__hasattr__ and __delattr__ methods. But I'd like to ask the
author and reviewer of the patch if they remember why this
delegation was added in the first place, and if there's
something that might be broken by my proposed fix.
|