mirror of
https://github.com/django/django.git
synced 2025-04-01 12:06:43 +00:00
Refs #25665 -- Deprecated getters/setters of Point coordinate properties.
This commit is contained in:
parent
b7177cc2a4
commit
7803f429a4
@ -1,9 +1,11 @@
|
|||||||
|
import warnings
|
||||||
from ctypes import c_uint
|
from ctypes import c_uint
|
||||||
|
|
||||||
from django.contrib.gis.geos import prototypes as capi
|
from django.contrib.gis.geos import prototypes as capi
|
||||||
from django.contrib.gis.geos.error import GEOSException
|
from django.contrib.gis.geos.error import GEOSException
|
||||||
from django.contrib.gis.geos.geometry import GEOSGeometry
|
from django.contrib.gis.geos.geometry import GEOSGeometry
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.deprecation import RemovedInDjango20Warning
|
||||||
from django.utils.six.moves import range
|
from django.utils.six.moves import range
|
||||||
|
|
||||||
|
|
||||||
@ -95,40 +97,79 @@ class Point(GEOSGeometry):
|
|||||||
|
|
||||||
_get_single_internal = _get_single_external
|
_get_single_internal = _get_single_external
|
||||||
|
|
||||||
def get_x(self):
|
@property
|
||||||
|
def x(self):
|
||||||
"Returns the X component of the Point."
|
"Returns the X component of the Point."
|
||||||
return self._cs.getOrdinate(0, 0)
|
return self._cs.getOrdinate(0, 0)
|
||||||
|
|
||||||
def set_x(self, value):
|
@x.setter
|
||||||
|
def x(self, value):
|
||||||
"Sets the X component of the Point."
|
"Sets the X component of the Point."
|
||||||
self._cs.setOrdinate(0, 0, value)
|
self._cs.setOrdinate(0, 0, value)
|
||||||
|
|
||||||
def get_y(self):
|
@property
|
||||||
|
def y(self):
|
||||||
"Returns the Y component of the Point."
|
"Returns the Y component of the Point."
|
||||||
return self._cs.getOrdinate(1, 0)
|
return self._cs.getOrdinate(1, 0)
|
||||||
|
|
||||||
def set_y(self, value):
|
@y.setter
|
||||||
|
def y(self, value):
|
||||||
"Sets the Y component of the Point."
|
"Sets the Y component of the Point."
|
||||||
self._cs.setOrdinate(1, 0, value)
|
self._cs.setOrdinate(1, 0, value)
|
||||||
|
|
||||||
def get_z(self):
|
@property
|
||||||
|
def z(self):
|
||||||
"Returns the Z component of the Point."
|
"Returns the Z component of the Point."
|
||||||
if self.hasz:
|
return self._cs.getOrdinate(2, 0) if self.hasz else None
|
||||||
return self._cs.getOrdinate(2, 0)
|
|
||||||
else:
|
@z.setter
|
||||||
return None
|
def z(self, value):
|
||||||
|
"Sets the Z component of the Point."
|
||||||
|
if not self.hasz:
|
||||||
|
raise GEOSException('Cannot set Z on 2D Point.')
|
||||||
|
self._cs.setOrdinate(2, 0, value)
|
||||||
|
|
||||||
|
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):
|
def set_z(self, value):
|
||||||
"Sets the Z component of the Point."
|
warnings.warn(
|
||||||
if self.hasz:
|
"`set_z()` is deprecated, use the `z` property instead.",
|
||||||
self._cs.setOrdinate(2, 0, value)
|
RemovedInDjango20Warning, 2
|
||||||
else:
|
)
|
||||||
raise GEOSException('Cannot set Z on 2D Point.')
|
self.z = value
|
||||||
|
|
||||||
# X, Y, Z properties
|
|
||||||
x = property(get_x, set_x)
|
|
||||||
y = property(get_y, set_y)
|
|
||||||
z = property(get_z, set_z)
|
|
||||||
|
|
||||||
# ### Tuple setting and retrieval routines. ###
|
# ### Tuple setting and retrieval routines. ###
|
||||||
def get_coords(self):
|
def get_coords(self):
|
||||||
|
@ -115,6 +115,9 @@ details on these changes.
|
|||||||
* The ``get_srid()`` and ``set_srid()`` methods of
|
* The ``get_srid()`` and ``set_srid()`` methods of
|
||||||
``django.contrib.gis.geos.GEOSGeometry`` will be removed.
|
``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:
|
.. _deprecation-removed-in-1.10:
|
||||||
|
|
||||||
1.10
|
1.10
|
||||||
|
@ -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
|
:class:`~django.contrib.gis.geos.GEOSGeometry` are deprecated in favor
|
||||||
of the :attr:`~django.contrib.gis.geos.GEOSGeometry.srid` property.
|
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
|
Miscellaneous
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -862,7 +862,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
|
|||||||
|
|
||||||
# Testing __getitem__ (doesn't work on Point or Polygon)
|
# Testing __getitem__ (doesn't work on Point or Polygon)
|
||||||
if isinstance(g, Point):
|
if isinstance(g, Point):
|
||||||
self.assertRaises(IndexError, g.get_x)
|
with self.assertRaises(IndexError):
|
||||||
|
g.x
|
||||||
elif isinstance(g, Polygon):
|
elif isinstance(g, Polygon):
|
||||||
lr = g.shell
|
lr = g.shell
|
||||||
self.assertEqual('LINEARRING EMPTY', lr.wkt)
|
self.assertEqual('LINEARRING EMPTY', lr.wkt)
|
||||||
@ -1148,3 +1149,13 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
|
|||||||
|
|
||||||
p.set_srid(321)
|
p.set_srid(321)
|
||||||
self.assertEqual(p.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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user