Commit 0b5d32fa authored by Tim Graham's avatar Tim Graham
Browse files

Fixed #25611 -- Standardized descriptor signatures.

parent 34af2bc5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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

+7 −7
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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

+4 −4
Original line number Diff line number Diff line
@@ -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.

Loading