Changeset 139

Show
Ignore:
Timestamp:
05/05/02 14:04:03 (6 years ago)
Author:
sholloway
Message:

Found a potentially devestating bug in the weakbind code. Python 2.2 object derived classes return false for isinstance(object(), types.InstanceType?), causing big problems...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/WeakBind.py

    r104 r139  
    4242#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4343 
    44 typesRequireBinding = (types.MethodType, types.UnboundMethodType, types.InstanceType) 
     44typesMethods = (types.MethodType, types.UnboundMethodType) 
     45typesInstances = (object, types.InstanceType) 
     46typesRequireBinding = typesMethods + typesInstances 
    4547 
    4648#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4749 
    4850class BoundCallableBase(object): 
     51    """Ultimate baseclass of BoundCallable objects.  Derive from this object if the class  
     52    handles references to itself, by itself.""" 
    4953    pass 
    5054 
     
    5357class BoundCallable(BoundCallableBase): 
    5458    im_self = None 
     59    im_func = None 
    5560 
    5661    def __init__(self, callback): 
    57         if isinstance(callback, (types.MethodType, types.UnboundMethodType)): 
     62        if callback is None: 
     63            self.im_func = None 
     64        elif isinstance(callback, typesMethods): 
    5865            if callback.im_self is not None:  
    5966                self.im_self = weakref.ref(callback.im_self) 
    6067            self.im_func = callback.im_func 
    61         elif isinstance(callback, types.InstanceType): 
     68        elif isinstance(callback, typesInstances): 
    6269            self.im_self = weakref.ref(callback) 
    6370            self.im_func = None 
    6471        else: 
    6572            self.im_func = callback 
    66   
     73 
    6774    def __nonzero__(self): 
    68         result = self.im_func and (not self.im_self or self.im_self() is not None) and 1 or 0 
    69         return result 
     75        if self.im_self is not None: 
     76            return self.im_self() is not None and 1 or 0 
     77        else:  
     78            return self.im_func and 1 or 0 
    7079 
    7180    def __call__(self, *args, **kw):