Skip to content

Commit 0618eca

Browse files
authored
api cleanup: remove ndsl/units.py (NOAA-GFDL#248)
The functions are all unused (I've checked pyFV3, pySHiELD, and pace) and should be removed to keep API surface as small as possible. In the future we envision NDSL to come with much more potent type checking for units. Until then, if really needed, these functions can be implemented trivially by dsl users. Co-authored-by: Roman Cattaneo <1116746+romanc@users.noreply.github.com>
1 parent 204a5dd commit 0618eca

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

ndsl/units.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
import warnings
2+
3+
14
def ensure_equal_units(units1: str, units2: str) -> None:
5+
warnings.warn(
6+
"`ensure_equal_units` is unused and usage is discouraged. The function "
7+
"will be removed in the next version of NDSL.",
8+
DeprecationWarning,
9+
stacklevel=2,
10+
)
211
if not units_are_equal(units1, units2):
312
raise UnitsError(f"incompatible units {units1} and {units2}")
413

514

615
def units_are_equal(units1: str, units2: str) -> bool:
16+
warnings.warn(
17+
"`units_are_equal` is unused and usage is discouraged. The function will "
18+
"be removed in the next version of NDSL.",
19+
DeprecationWarning,
20+
stacklevel=2,
21+
)
722
return units1.strip() == units2.strip()
823

924

1025
class UnitsError(Exception):
11-
pass
26+
def __init__(self, *args) -> None:
27+
warnings.warn(
28+
"`UnitsError` is unused and usage is discouraged. The class will be "
29+
"removed in the next version of NDSL.",
30+
DeprecationWarning,
31+
stacklevel=2,
32+
)
33+
super().__init__(*args)

tests/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from ndsl.units import UnitsError, ensure_equal_units, units_are_equal
4+
5+
6+
def test_UnitsError_is_deprecated() -> None:
7+
with pytest.deprecated_call():
8+
UnitsError()
9+
10+
11+
def test_units_are_equal_is_deprecated() -> None:
12+
with pytest.deprecated_call():
13+
units_are_equal("asdf", "asdf")
14+
15+
16+
def test_ensure_equal_units_is_deprecated() -> None:
17+
with pytest.deprecated_call():
18+
ensure_equal_units("asdf", "asdf")

0 commit comments

Comments
 (0)