Skip to content

Commit 4c6413d

Browse files
authored
refactor: Disallow value as string (#232)
* refactor: Disallow value as string * add a test * update error
1 parent 44bd57f commit 4c6413d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/ansys/units/quantity.py

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __init__(
7878
raise InsufficientArguments()
7979

8080
if not isinstance(value, (float, int)):
81+
if isinstance(value, str):
82+
raise TypeError("value should be either float, int or [float, int].")
8183
if _array:
8284
if isinstance(value, _array.ndarray):
8385
self._value = value

tests/test_quantity.py

+5
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,8 @@ def test_error_messages():
589589

590590
e4 = RequiresUniqueDimensions(Unit("mm"), Unit("m"))
591591
assert str(e4) == "For 'mm' to be added 'm' must be removed."
592+
593+
594+
def test_value_as_string():
595+
with pytest.raises(TypeError):
596+
q = Quantity("string", "m")

0 commit comments

Comments
 (0)