Skip to content

Commit

Permalink
Fix return type of Quantity.extract()
Browse files Browse the repository at this point in the history
Update copyright year
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Feb 1, 2024
1 parent ee7f85a commit 6cf26de
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.6", "3.x"]
max-parallel: 6

steps:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2023 Kenneth S. Kundert
Copyright (c) 2016-2024 Kenneth S. Kundert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

# General information about the project.
project = u'quantiphy'
copyright = u'2017-2023, Ken Kundert'
copyright = u'2017-2024, Ken Kundert'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
5 changes: 0 additions & 5 deletions doc/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2739,11 +2739,6 @@ corresponding Python error for compatibility with existing code. It is
recommended that new code catch the *QuantiPhy* specific exceptions rather than
the generic Python exceptions as their use will be deprecated in the future.

.. note::

It is expected that in release 2.20, expected in the first half of 2023, the
exceptions will no longer inherit from the generic Python exceptions.

*QuantiPhy* employs the following exceptions:

:class:`ExpectedQuantity`:
Expand Down
18 changes: 8 additions & 10 deletions quantiphy/quantiphy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

# MIT License {{{1
# Copyright (C) 2016-2023 Kenneth S. Kundert
# Copyright (C) 2016-2024 Kenneth S. Kundert
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -1773,9 +1773,10 @@ def scale(self, scale, cls=None):
the units, so the second argument is redundant and will eventually
be deprecated. The function returns two values, the value and
units of the new value.
- If a string, it is taken to the be desired units. This value along
with the units of the quantity are used to select a known unit
conversion, which is applied to create the new value.
- If a string, it is taken to the be desired units, perhaps with a
scale factor. This value along with the units of the quantity are
used to select a known unit conversion, which is applied to create
the new value.
- If a quantity, the units are ignored and the scale is treated as
if were specified as a unitless float.
- If a subclass of :class:`Quantity` that includes units, the units
Expand Down Expand Up @@ -1851,13 +1852,10 @@ def add(self, addend, check_units=False):

try:
if check_units and self.units != addend.units:
raise IncompatibleUnits(self.units, addend.units)
raise IncompatibleUnits(self, addend)
except AttributeError:
if check_units == 'strict':
raise IncompatibleUnits(
getattr(self, 'units', None),
getattr(addend, 'units', None)
)
raise IncompatibleUnits(self, addend)
new = self.__class__(self.real + addend, self.units)
new._inherit_attributes(self)
return new
Expand Down Expand Up @@ -3424,7 +3422,7 @@ def convert(self, value=1, from_units=None, to_units=None):
elif from_units in self.to_units and value.units in self.to_units:
pass
else:
raise IncompatibleUnits(value.units, from_units)
raise IncompatibleUnits(value, from_units)

if to_units is None and from_units is None:
to_units = self.to_units[0]
Expand Down
2 changes: 1 addition & 1 deletion quantiphy/quantiphy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Quantity(float):
text: str,
predefined: dict = ...,
**kwargs,
): ...
) -> dict[str, Quantity]: ...

@staticmethod
def map_sf_to_sci_notation(sf: str): ...
Expand Down
4 changes: 2 additions & 2 deletions tests/test_unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ def test_add():

with pytest.raises(IncompatibleUnits) as exception:
total = total.add(Quantity(contribution, 'lbs'), check_units=True)
assert str(exception.value) == "incompatible units ($ and lbs)."
assert str(exception.value) == "incompatible units ($44.04 and 9.89 lbs)."
assert isinstance(exception.value, IncompatibleUnits)
assert isinstance(exception.value, QuantiPhyError)
assert isinstance(exception.value, TypeError)
assert exception.value.args == ('$', 'lbs')
assert "{} and {}".format(*exception.value.args) == "$44.04 and 9.89 lbs"

def test_linear_conversion():
Quantity.reset_prefs()
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ envlist = lint, pytest, mypy
isolated_build = True

[testenv:lint]
deps = pylama
deps =
setuptools
pylama
skip_install = true
commands = pylama --ignore E226,E501,C901,E116,E251,E203 quantiphy/*.py

Expand Down

0 comments on commit 6cf26de

Please sign in to comment.