From 7a452c5ce295679307bd81dd9b5f37b3cf762acf Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Thu, 5 Nov 2015 10:37:51 +0500 Subject: [PATCH] Fixed #25665 -- Deprecated getter/setter of Point.tuple. --- django/contrib/gis/geos/point.py | 21 ++++++++++++++++++--- docs/internals/deprecation.txt | 3 +++ docs/releases/1.10.txt | 4 ++++ tests/gis_tests/geos_tests/test_geos.py | 17 +++++++++++++---- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py index beccfb0af5..34a955e924 100644 --- a/django/contrib/gis/geos/point.py +++ b/django/contrib/gis/geos/point.py @@ -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 diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 77ab15eb3c..2b21b98179 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -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 diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 0329456be0..d16075f00f 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -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 ~~~~~~~~~~~~~ diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 9b1a7e384f..683d00c89f 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -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))