Fixed #25611 -- Standardized descriptor signatures.
This commit is contained in:
parent
34af2bc523
commit
0b5d32faca
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue