Ticket #20651: pep8.patch

File pep8.patch, 4.9 KB (added by Maxime Arthaud <maxime.arthaud@…>, 11 years ago)

Patch file

  • django/dispatch/saferef.py

    From a95d12c54ad7fe696deb6f16183e3ecb078bf92c Mon Sep 17 00:00:00 2001
    From: Maxima <maxime.arthaud@gmail.com>
    Date: Mon, 24 Jun 2013 21:02:53 +0200
    Subject: [PATCH] PEP 8 compliance.
    
    ---
     django/dispatch/saferef.py | 34 +++++++++++++++++-----------------
     1 file changed, 17 insertions(+), 17 deletions(-)
    
    diff --git a/django/dispatch/saferef.py b/django/dispatch/saferef.py
    index c7731d4..d27120c 100644
    a b def safeRef(target, onDelete = None):  
    2323        if target.__self__ is not None:
    2424            # Turn a bound method into a BoundMethodWeakref instance.
    2525            # Keep track of these instances for lookup by disconnect().
    26             assert hasattr(target, '__func__'), """safeRef target %r has __self__, but no __func__, don't know how to create reference"""%( target,)
     26            assert hasattr(target, '__func__'), """safeRef target %r has __self__, but no __func__, don't know how to create reference""" % (target,)
    2727            reference = get_bound_method_weakref(
    2828                target=target,
    2929                onDelete=onDelete
    def safeRef(target, onDelete = None):  
    3232    if callable(onDelete):
    3333        return weakref.ref(target, onDelete)
    3434    else:
    35         return weakref.ref( target )
     35        return weakref.ref(target)
    3636
    3737class BoundMethodWeakref(object):
    3838    """'Safe' and reusable weak references to instance methods
    class BoundMethodWeakref(object):  
    7070
    7171    _allInstances = weakref.WeakValueDictionary()
    7272
    73     def __new__( cls, target, onDelete=None, *arguments,**named ):
     73    def __new__(cls, target, onDelete=None, *arguments, **named):
    7474        """Create new instance or return current instance
    7575
    7676        Basically this method of construction allows us to
    class BoundMethodWeakref(object):  
    8383        of already-referenced methods.
    8484        """
    8585        key = cls.calculateKey(target)
    86         current =cls._allInstances.get(key)
     86        current = cls._allInstances.get(key)
    8787        if current is not None:
    88             current.deletionMethods.append( onDelete)
     88            current.deletionMethods.append(onDelete)
    8989            return current
    9090        else:
    91             base = super( BoundMethodWeakref, cls).__new__( cls )
     91            base = super(BoundMethodWeakref, cls).__new__(cls)
    9292            cls._allInstances[key] = base
    93             base.__init__( target, onDelete, *arguments,**named)
     93            base.__init__(target, onDelete, *arguments, **named)
    9494            return base
    9595
    9696    def __init__(self, target, onDelete=None):
    class BoundMethodWeakref(object):  
    112112            methods = self.deletionMethods[:]
    113113            del self.deletionMethods[:]
    114114            try:
    115                 del self.__class__._allInstances[ self.key ]
     115                del self.__class__._allInstances[self.key]
    116116            except KeyError:
    117117                pass
    118118            for function in methods:
    119119                try:
    120                     if callable( function ):
    121                         function( self )
     120                    if callable(function):
     121                        function(self)
    122122                except Exception as e:
    123123                    try:
    124124                        traceback.print_exc()
    class BoundMethodWeakref(object):  
    127127                            self, function, e)
    128128                        )
    129129        self.deletionMethods = [onDelete]
    130         self.key = self.calculateKey( target )
     130        self.key = self.calculateKey(target)
    131131        self.weakSelf = weakref.ref(target.__self__, remove)
    132132        self.weakFunc = weakref.ref(target.__func__, remove)
    133133        self.selfName = str(target.__self__)
    134134        self.funcName = str(target.__func__.__name__)
    135135
    136     def calculateKey( cls, target ):
     136    def calculateKey(cls, target):
    137137        """Calculate the reference key for this reference
    138138
    139139        Currently this is a two-tuple of the id()'s of the
    140140        target object and the target function respectively.
    141141        """
    142         return (id(target.__self__),id(target.__func__))
    143     calculateKey = classmethod( calculateKey )
     142        return (id(target.__self__), id(target.__func__))
     143    calculateKey = classmethod(calculateKey)
    144144
    145145    def __str__(self):
    146146        """Give a friendly representation of the object"""
    147         return """%s( %s.%s )"""%(
     147        return """%s( %s.%s )""" % (
    148148            self.__class__.__name__,
    149149            self.selfName,
    150150            self.funcName,
    class BoundMethodWeakref(object):  
    155155    def __hash__(self):
    156156        return hash(self.key)
    157157
    158     def __bool__( self ):
     158    def __bool__(self):
    159159        """Whether we are still a valid reference"""
    160160        return self() is not None
    161161
    162     def __nonzero__(self):      # Python 2 compatibility
     162    def __nonzero__(self): # Python 2 compatibility
    163163        return type(self).__bool__(self)
    164164
    165165    def __eq__(self, other):
Back to Top