summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2015-11-05 08:45:42 +0500
committerTim Graham <timograham@gmail.com>2015-11-18 11:57:26 -0500
commit7803f429a4d435623cb7b91dd324d3aadad87380 (patch)
treec086fb15a4b9d873dde92598823055057f4e46ba
parentb7177cc2a422a0183c8f2d56eceb6b9323c6f959 (diff)
Refs #25665 -- Deprecated getters/setters of Point coordinate properties.
-rw-r--r--django/contrib/gis/geos/point.py75
-rw-r--r--docs/internals/deprecation.txt3
-rw-r--r--docs/releases/1.10.txt4
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py13
4 files changed, 77 insertions, 18 deletions
diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py
index 65cf1344c9..beccfb0af5 100644
--- a/django/contrib/gis/geos/point.py
+++ b/django/contrib/gis/geos/point.py
@@ -1,9 +1,11 @@
+import warnings
from ctypes import c_uint
from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.geometry import GEOSGeometry
from django.utils import six
+from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.six.moves import range
@@ -95,40 +97,79 @@ class Point(GEOSGeometry):
_get_single_internal = _get_single_external
- def get_x(self):
+ @property
+ def x(self):
"Returns the X component of the Point."
return self._cs.getOrdinate(0, 0)
- def set_x(self, value):
+ @x.setter
+ def x(self, value):
"Sets the X component of the Point."
self._cs.setOrdinate(0, 0, value)
- def get_y(self):
+ @property
+ def y(self):
"Returns the Y component of the Point."
return self._cs.getOrdinate(1, 0)
- def set_y(self, value):
+ @y.setter
+ def y(self, value):
"Sets the Y component of the Point."
self._cs.setOrdinate(1, 0, value)
- def get_z(self):
+ @property
+ def z(self):
"Returns the Z component of the Point."
- if self.hasz:
- return self._cs.getOrdinate(2, 0)
- else:
- return None
+ return self._cs.getOrdinate(2, 0) if self.hasz else None
- def set_z(self, value):
+ @z.setter
+ def z(self, value):
"Sets the Z component of the Point."
- if self.hasz:
- self._cs.setOrdinate(2, 0, value)
- else:
+ if not self.hasz:
raise GEOSException('Cannot set Z on 2D Point.')
+ self._cs.setOrdinate(2, 0, value)
- # X, Y, Z properties
- x = property(get_x, set_x)
- y = property(get_y, set_y)
- z = property(get_z, set_z)
+ def get_x(self):
+ warnings.warn(
+ "`get_x()` is deprecated, use the `x` property instead.",
+ RemovedInDjango20Warning, 2
+ )
+ return self.x
+
+ def set_x(self, value):
+ warnings.warn(
+ "`set_x()` is deprecated, use the `x` property instead.",
+ RemovedInDjango20Warning, 2
+ )
+ self.x = value
+
+ def get_y(self):
+ warnings.warn(
+ "`get_y()` is deprecated, use the `y` property instead.",
+ RemovedInDjango20Warning, 2
+ )
+ return self.y
+
+ def set_y(self, value):
+ warnings.warn(
+ "`set_y()` is deprecated, use the `y` property instead.",
+ RemovedInDjango20Warning, 2
+ )
+ self.y = value
+
+ def get_z(self):
+ warnings.warn(
+ "`get_z()` is deprecated, use the `z` property instead.",
+ RemovedInDjango20Warning, 2
+ )
+ return self.z
+
+ def set_z(self, value):
+ warnings.warn(
+ "`set_z()` is deprecated, use the `z` property instead.",
+ RemovedInDjango20Warning, 2
+ )
+ self.z = value
# ### Tuple setting and retrieval routines. ###
def get_coords(self):
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index db2bf02af2..77ab15eb3c 100644
--- a/docs/internals/deprecation.txt
+++ b/docs/internals/deprecation.txt
@@ -115,6 +115,9 @@ details on these changes.
* The ``get_srid()`` and ``set_srid()`` methods of
``django.contrib.gis.geos.GEOSGeometry`` will be removed.
+* The ``get_x()``, ``set_x()``, ``get_y()``, ``set_y()``, ``get_z()``, and
+ ``set_z()`` 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 d4a0e63094..0329456be0 100644
--- a/docs/releases/1.10.txt
+++ b/docs/releases/1.10.txt
@@ -335,6 +335,10 @@ This prevents confusion about an assignment resulting in an implicit save.
:class:`~django.contrib.gis.geos.GEOSGeometry` are deprecated in favor
of the :attr:`~django.contrib.gis.geos.GEOSGeometry.srid` property.
+* The ``get_x()``, ``set_x()``, ``get_y()``, ``set_y()``, ``get_z()``, and
+ ``set_z()`` methods of :class:`~django.contrib.gis.geos.Point` are deprecated
+ in favor of the ``x``, ``y``, and ``z`` properties.
+
Miscellaneous
~~~~~~~~~~~~~
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 504676d4c6..9b1a7e384f 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -862,7 +862,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Testing __getitem__ (doesn't work on Point or Polygon)
if isinstance(g, Point):
- self.assertRaises(IndexError, g.get_x)
+ with self.assertRaises(IndexError):
+ g.x
elif isinstance(g, Polygon):
lr = g.shell
self.assertEqual('LINEARRING EMPTY', lr.wkt)
@@ -1148,3 +1149,13 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
p.set_srid(321)
self.assertEqual(p.srid, 321)
+
+ @ignore_warnings(category=RemovedInDjango20Warning)
+ def test_deprecated_point_coordinate_getters_setters(self):
+ p = Point(1, 2, 3)
+ 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))