Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[py3] Made gis.measure Python 3-compatible

  • Loading branch information...
commit 2da3af23aa10af3e06536a46134b1053f80eb8b2 1 parent fa4cb34
@claudep claudep authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 django/contrib/gis/measure.py
View
12 django/contrib/gis/measure.py
@@ -143,7 +143,7 @@ def __imul__(self, other):
def __rmul__(self, other):
return self * other
- def __div__(self, other):
+ def __truediv__(self, other):
if isinstance(other, self.__class__):
return self.standard / other.standard
if isinstance(other, NUMERIC_TYPES):
@@ -151,16 +151,19 @@ def __div__(self, other):
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided with number or %(class)s' % {"class":pretty_name(self)})
+ __div__ = __truediv__ # Python 2 compatibility
- def __idiv__(self, other):
+ def __itruediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
self.standard /= float(other)
return self
else:
raise TypeError('%(class)s must be divided with number' % {"class":pretty_name(self)})
+ __idiv__ = __itruediv__ # Python 2 compatibility
- def __nonzero__(self):
+ def __bool__(self):
return bool(self.standard)
+ __nonzero__ = __bool__ # Python 2 compatibility
def default_units(self, kwargs):
"""
@@ -305,12 +308,13 @@ class Area(MeasureBase):
ALIAS = dict([(k, '%s%s' % (AREA_PREFIX, v)) for k, v in Distance.ALIAS.items()])
LALIAS = dict([(k.lower(), v) for k, v in ALIAS.items()])
- def __div__(self, other):
+ def __truediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided by a number' % {"class":pretty_name(self)})
+ __div__ = __truediv__ # Python 2 compatibility
# Shortcuts
Please sign in to comment.
Something went wrong with that request. Please try again.