Skip to content

Commit 201a63e

Browse files
committed
Add deprication warnings to non-float Coordinates
1 parent 9d3a85a commit 201a63e

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/funlib/geometry/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
from .coordinate import Coordinate # noqa
1+
import warnings
2+
3+
from .coordinate import Coordinate as _Coordinate # noqa
24
from .float_coordinate import FloatCoordinate # noqa
35
from .float_roi import FloatRoi # noqa
46
from .roi import Roi # noqa
57

8+
__all__ = ["Coordinate", "FloatCoordinate", "Roi", "FloatRoi"]
9+
610
__major__ = 0
711
__minor__ = 3
812
__patch__ = 0
913
__tag__ = ""
1014
__version__ = "{}.{}.{}{}".format(__major__, __minor__, __patch__, __tag__).strip(".")
15+
16+
17+
def __getattr__(name):
18+
if name == "Coordinate":
19+
warnings.warn(
20+
"Coordinate is deprecated, use FloatCoordinate instead. "
21+
"Coordinate will be removed in a future version.",
22+
DeprecationWarning,
23+
stacklevel=2,
24+
)
25+
return _Coordinate
26+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

src/funlib/geometry/coordinate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ def __mul__(self, other: Union[Any, "Coordinate", int, float]) -> "Coordinate":
137137

138138
def __div__(self, other: Union["Coordinate", int, float]) -> "Coordinate":
139139
if isinstance(other, Coordinate):
140+
if type(self) is not type(other):
141+
raise TypeError(
142+
f"cannot use / between {type(self).__name__} and "
143+
f"{type(other).__name__}; convert to the same type or use //"
144+
)
140145
assert self.dims == other.dims, (
141146
"can only divide Coordinate of equal dimensions"
142147
)
@@ -156,6 +161,11 @@ def __div__(self, other: Union["Coordinate", int, float]) -> "Coordinate":
156161

157162
def __truediv__(self, other: Union["Coordinate", int, float]) -> "Coordinate":
158163
if isinstance(other, Coordinate):
164+
if type(self) is not type(other):
165+
raise TypeError(
166+
f"cannot use / between {type(self).__name__} and "
167+
f"{type(other).__name__}; convert to the same type or use //"
168+
)
159169
assert self.dims == other.dims, (
160170
"can only divide Coordinate of equal dimensions"
161171
)

0 commit comments

Comments
 (0)