Fixed #25665 -- Deprecated getter/setter of Point.tuple.

This commit is contained in:
Sergey Fedoseev 2015-11-05 10:37:51 +05:00 committed by Tim Graham
parent 7803f429a4
commit 7a452c5ce2
4 changed files with 38 additions and 7 deletions

View File

@ -172,14 +172,29 @@ class Point(GEOSGeometry):
self.z = value
# ### Tuple setting and retrieval routines. ###
def get_coords(self):
@property
def tuple(self):
"Returns a tuple of the point."
return self._cs.tuple
def set_coords(self, tup):
@tuple.setter
def tuple(self, tup):
"Sets the coordinates of the point with the given tuple."
self._cs[0] = tup
def get_coords(self):
warnings.warn(
"`get_coords()` is deprecated, use the `tuple` property instead.",
RemovedInDjango20Warning, 2
)
return self.tuple
def set_coords(self, tup):
warnings.warn(
"`set_coords()` is deprecated, use the `tuple` property instead.",
RemovedInDjango20Warning, 2
)
self.tuple = tup
# The tuple and coords properties
tuple = property(get_coords, set_coords)
coords = tuple

View File

@ -118,6 +118,9 @@ details on these changes.
* The ``get_x()``, ``set_x()``, ``get_y()``, ``set_y()``, ``get_z()``, and
``set_z()`` methods of ``django.contrib.gis.geos.Point`` will be removed.
* The ``get_coords()`` and ``set_coords()`` methods of
``django.contrib.gis.geos.Point`` will be removed.
.. _deprecation-removed-in-1.10:
1.10

View File

@ -339,6 +339,10 @@ This prevents confusion about an assignment resulting in an implicit save.
``set_z()`` methods of :class:`~django.contrib.gis.geos.Point` are deprecated
in favor of the ``x``, ``y``, and ``z`` properties.
* The ``get_coords()`` and ``set_coords()`` methods of
:class:`~django.contrib.gis.geos.Point` are deprecated in favor of the
``tuple`` property.
Miscellaneous
~~~~~~~~~~~~~

View File

@ -787,7 +787,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Testing a 3D Point
pnt = Point(2, 3, 8)
self.assertEqual((2., 3., 8.), pnt.coords)
self.assertRaises(TypeError, pnt.set_coords, (1., 2.))
with self.assertRaises(TypeError):
pnt.tuple = (1., 2.)
pnt.coords = (1., 2., 3.)
self.assertEqual((1., 2., 3.), pnt.coords)
@ -1156,6 +1157,14 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual((p.get_x(), p.get_y(), p.get_z()), (p.x, p.y, p.z))
p.set_x(3)
p.set_y(1)
p.set_z(2)
self.assertEqual((p.x, p.y, p.z), (3, 1, 2))
p.set_y(2)
p.set_z(1)
self.assertEqual((p.x, p.y, p.z), (3, 2, 1))
@ignore_warnings(category=RemovedInDjango20Warning)
def test_deprecated_point_tuple_getters_setters(self):
p = Point(1, 2, 3)
self.assertEqual(p.get_coords(), (p.x, p.y, p.z))
p.set_coords((3, 2, 1))
self.assertEqual(p.get_coords(), (3, 2, 1))