diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index bb2565653b..f40c2c713c 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -235,7 +235,7 @@ class GenericForeignKey(object): def is_cached(self, instance): return hasattr(instance, self.cache_attr) - def __get__(self, instance, instance_type=None): + def __get__(self, instance, cls=None): if instance is None: return self diff --git a/django/contrib/gis/db/models/proxy.py b/django/contrib/gis/db/models/proxy.py index 494d4a949d..1dbcaee26a 100644 --- a/django/contrib/gis/db/models/proxy.py +++ b/django/contrib/gis/db/models/proxy.py @@ -17,19 +17,19 @@ class SpatialProxy(object): self._field = field self._klass = klass - def __get__(self, obj, type=None): + def __get__(self, instance, cls=None): """ This accessor retrieves the geometry or raster, initializing it using the corresponding class specified during initialization and the value of the field. Currently, GEOS or OGR geometries as well as GDALRasters are supported. """ - if obj is None: + if instance is None: # Accessed on a class, not an instance return self # Getting the value of the field. - geo_value = obj.__dict__[self._field.attname] + geo_value = instance.__dict__[self._field.attname] if isinstance(geo_value, self._klass): geo_obj = geo_value @@ -39,10 +39,10 @@ class SpatialProxy(object): # Otherwise, a geometry or raster object is built using the field's # contents, and the model's corresponding attribute is set. geo_obj = self._klass(geo_value) - setattr(obj, self._field.attname, geo_obj) + setattr(instance, self._field.attname, geo_obj) return geo_obj - def __set__(self, obj, value): + def __set__(self, instance, value): """ This accessor sets the proxied geometry or raster with the corresponding class specified during initialization. @@ -68,8 +68,8 @@ class SpatialProxy(object): pass else: raise TypeError('Cannot set %s SpatialProxy (%s) with value of type: %s' % ( - obj.__class__.__name__, gtype, type(value))) + instance.__class__.__name__, gtype, type(value))) # Setting the objects dictionary with the value, and returning. - obj.__dict__[self._field.attname] = value + instance.__dict__[self._field.attname] = value return value diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index cc9e6d7c18..d286ad0fff 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -70,7 +70,7 @@ IntegrityError = Database.IntegrityError class _UninitializedOperatorsDescriptor(object): - def __get__(self, instance, owner): + def __get__(self, instance, cls=None): # If connection.operators is looked up before a connection has been # created, transparently initialize connection.operators to avert an # AttributeError. diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index c4c44f18f8..cc8fe181ba 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -155,7 +155,7 @@ class FileDescriptor(object): def __init__(self, field): self.field = field - def __get__(self, instance=None, owner=None): + def __get__(self, instance, cls=None): if instance is None: return self diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py index 486829386f..b27b92e405 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -140,7 +140,7 @@ class ForwardManyToOneDescriptor(object): setattr(rel_obj, rel_obj_cache_name, instance) return queryset, rel_obj_attr, instance_attr, True, self.cache_name - def __get__(self, instance, instance_type=None): + def __get__(self, instance, cls=None): """ Get the related instance through the forward relation. @@ -148,7 +148,7 @@ class ForwardManyToOneDescriptor(object): - ``self`` is the descriptor managing the ``parent`` attribute - ``instance`` is the ``child`` instance - - ``instance_type`` in the ``Child`` class (we don't need it) + - ``cls`` is the ``Child`` class (we don't need it) """ if instance is None: return self @@ -311,7 +311,7 @@ class ReverseOneToOneDescriptor(object): setattr(rel_obj, rel_obj_cache_name, instance) return queryset, rel_obj_attr, instance_attr, True, self.cache_name - def __get__(self, instance, instance_type=None): + def __get__(self, instance, cls=None): """ Get the related instance through the reverse relation. @@ -452,7 +452,7 @@ class ReverseManyToOneDescriptor(object): self.rel, ) - def __get__(self, instance, instance_type=None): + def __get__(self, instance, cls=None): """ Get the related objects through the reverse relation. diff --git a/django/db/models/manager.py b/django/db/models/manager.py index eb013fd87c..4636869a12 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -245,9 +245,9 @@ class ManagerDescriptor(object): def __init__(self, manager): self.manager = manager - def __get__(self, instance, type=None): + def __get__(self, instance, cls=None): if instance is not None: - raise AttributeError("Manager isn't accessible via %s instances" % type.__name__) + raise AttributeError("Manager isn't accessible via %s instances" % cls.__name__) return self.manager @@ -257,7 +257,7 @@ class AbstractManagerDescriptor(object): def __init__(self, model): self.model = model - def __get__(self, instance, type=None): + def __get__(self, instance, cls=None): raise AttributeError("Manager isn't available; %s is abstract" % ( self.model._meta.object_name, )) @@ -269,7 +269,7 @@ class SwappedManagerDescriptor(object): def __init__(self, model): self.model = model - def __get__(self, instance, type=None): + def __get__(self, instance, cls=None): raise AttributeError( "Manager isn't available; '%s.%s' has been swapped for '%s'" % ( self.model._meta.app_label, diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 8e303e8f8a..1cd4e579d5 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -121,7 +121,7 @@ class DeferredAttribute(object): def __init__(self, field_name, model): self.field_name = field_name - def __get__(self, instance, owner): + def __get__(self, instance, cls=None): """ Retrieves and caches the value from the datastore on the first lookup. Returns the cached value. diff --git a/django/test/testcases.py b/django/test/testcases.py index 675ed7b6f7..7bfe9ea18f 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1053,7 +1053,7 @@ class CheckCondition(object): def __init__(self, cond_func): self.cond_func = cond_func - def __get__(self, obj, objtype): + def __get__(self, instance, cls=None): return self.cond_func() diff --git a/django/utils/decorators.py b/django/utils/decorators.py index 4e2d0a179e..87a702d3d8 100644 --- a/django/utils/decorators.py +++ b/django/utils/decorators.py @@ -11,10 +11,10 @@ from django.utils import six class classonlymethod(classmethod): - def __get__(self, instance, owner): + def __get__(self, instance, cls=None): if instance is not None: raise AttributeError("This method is available only on the class, not on instances.") - return super(classonlymethod, self).__get__(instance, owner) + return super(classonlymethod, self).__get__(instance, cls) def method_decorator(decorator, name=''): @@ -189,8 +189,8 @@ class classproperty(object): def __init__(self, method=None): self.fget = method - def __get__(self, instance, owner): - return self.fget(owner) + def __get__(self, instance, cls=None): + return self.fget(cls) def getter(self, method): self.fget = method diff --git a/django/utils/functional.py b/django/utils/functional.py index 9738d20646..7b566e429f 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -27,7 +27,7 @@ class cached_property(object): self.__doc__ = getattr(func, '__doc__') self.name = name or func.__name__ - def __get__(self, instance, type=None): + def __get__(self, instance, cls=None): if instance is None: return self res = instance.__dict__[self.name] = self.func(instance) diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index 3414264f72..d23d700201 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -286,7 +286,7 @@ class MethodDecoratorTests(SimpleTestCase): def __call__(self, arg): return self.wrapped(arg) - def __get__(self, instance, owner): + def __get__(self, instance, cls=None): return self class descriptor_wrapper(object): @@ -294,8 +294,8 @@ class MethodDecoratorTests(SimpleTestCase): self.wrapped = wrapped self.__name__ = wrapped.__name__ - def __get__(self, instance, owner): - return bound_wrapper(self.wrapped.__get__(instance, owner)) + def __get__(self, instance, cls=None): + return bound_wrapper(self.wrapped.__get__(instance, cls)) class Test(object): @method_dec