diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 858cc44..a601c4f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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: diff --git a/LICENSE b/LICENSE index 2c4da26..13e8ed2 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/doc/conf.py b/doc/conf.py index 4750fd5..c0468f0 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -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 diff --git a/doc/user.rst b/doc/user.rst index 19f14c2..7948932 100644 --- a/doc/user.rst +++ b/doc/user.rst @@ -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`: diff --git a/quantiphy/quantiphy.py b/quantiphy/quantiphy.py index 7f3698e..68ce8f5 100644 --- a/quantiphy/quantiphy.py +++ b/quantiphy/quantiphy.py @@ -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 @@ -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 @@ -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 @@ -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] diff --git a/quantiphy/quantiphy.pyi b/quantiphy/quantiphy.pyi index 24575db..3c42b72 100644 --- a/quantiphy/quantiphy.pyi +++ b/quantiphy/quantiphy.pyi @@ -161,7 +161,7 @@ class Quantity(float): text: str, predefined: dict = ..., **kwargs, - ): ... + ) -> dict[str, Quantity]: ... @staticmethod def map_sf_to_sci_notation(sf: str): ... diff --git a/tests/test_unit_conversion.py b/tests/test_unit_conversion.py index deea70b..7dacff5 100644 --- a/tests/test_unit_conversion.py +++ b/tests/test_unit_conversion.py @@ -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() diff --git a/tox.ini b/tox.ini index 92a8f1a..c914ca4 100644 --- a/tox.ini +++ b/tox.ini @@ -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