Skip to content

Commit

Permalink
addresses hgrecco#1845
Browse files Browse the repository at this point in the history
  • Loading branch information
jonemo committed Sep 22, 2023
1 parent a8906a5 commit 6feca1f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pint/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def add(self: Self, key: str, value: Number) -> Self:
UnitsContainer
A copy of this container.
"""
newval = self._d[key] + value
newval = self._d[key] + self._normalize_nonfloat_value(value)
new = self.copy()
if newval:
new._d[key] = newval
Expand Down Expand Up @@ -654,7 +654,7 @@ def __truediv__(self, other: Any):

new = self.copy()
for key, value in other.items():
new._d[key] -= value
new._d[key] -= self._normalize_nonfloat_value(value)
if new._d[key] == 0:
del new._d[key]

Expand All @@ -668,6 +668,11 @@ def __rtruediv__(self, other: Any):

return self**-1

def _normalize_nonfloat_value(self, value: Scalar) -> Scalar:
if not isinstance(value, int) and not isinstance(value, self._non_int_type):
return self._non_int_type(value) # type: ignore[no-any-return]
return value


class ParserHelper(UnitsContainer):
"""The ParserHelper stores in place the product of variables and
Expand Down

0 comments on commit 6feca1f

Please sign in to comment.