From 5d5451f506fc6a4b6e14c3162d4d9214ff0a4f5b Mon Sep 17 00:00:00 2001 From: Mauro Silberberg Date: Tue, 18 Feb 2025 17:56:43 -0300 Subject: [PATCH 1/5] lint: remove space in pre-commit-config ids --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b5ddef545..6a38c751d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,14 +25,14 @@ repos: language: system types: [text] - - id: ruff check + - id: ruff-check name: Lint with ruff entry: pixi run -e lint ruff check --force-exclude --fix language: system types_or: [python, pyi, jupyter] require_serial: true - - id: ruff format + - id: ruff-format name: Format with ruff entry: pixi run -e lint ruff format --force-exclude language: system From d09126a9435afbdb5083c0a8e1fe333ba6e6fff7 Mon Sep 17 00:00:00 2001 From: Mauro Silberberg Date: Tue, 18 Feb 2025 17:54:14 -0300 Subject: [PATCH 2/5] lint: ruff check --- docs/user/numpy.ipynb | 2 +- pint/delegates/formatter/_format_helpers.py | 2 +- pint/delegates/formatter/html.py | 2 +- pint/facets/context/objects.py | 4 +--- pint/facets/plain/quantity.py | 8 ++++---- pint/facets/plain/unit.py | 8 ++++---- pint/formatting.py | 2 +- pint/testsuite/test_compat_downcast.py | 2 +- pint/testsuite/test_converters.py | 18 ++++++++++-------- pint/testsuite/test_dask.py | 10 +++++----- pint/testsuite/test_diskcache.py | 5 ++--- pint/testsuite/test_non_int.py | 2 +- pint/testsuite/test_pitheorem.py | 8 ++++---- pint/testsuite/test_util.py | 14 +++++++------- 14 files changed, 43 insertions(+), 44 deletions(-) diff --git a/docs/user/numpy.ipynb b/docs/user/numpy.ipynb index 0b1b22197..2f2fec841 100644 --- a/docs/user/numpy.ipynb +++ b/docs/user/numpy.ipynb @@ -44,7 +44,7 @@ "Q_ = ureg.Quantity\n", "\n", "# Silence NEP 18 warning\n", - "import warnings\n", + "import warnings # noqa: E402\n", "\n", "with warnings.catch_warnings():\n", " warnings.simplefilter(\"ignore\")\n", diff --git a/pint/delegates/formatter/_format_helpers.py b/pint/delegates/formatter/_format_helpers.py index 8a2f37a59..da1c1f7f2 100644 --- a/pint/delegates/formatter/_format_helpers.py +++ b/pint/delegates/formatter/_format_helpers.py @@ -194,7 +194,7 @@ def formatter( """ if as_ratio: - fun = lambda x: exp_call(abs(x)) + fun = lambda x: exp_call(abs(x)) # noqa: E731 else: fun = exp_call diff --git a/pint/delegates/formatter/html.py b/pint/delegates/formatter/html.py index 7e5537fb1..2a751cd45 100644 --- a/pint/delegates/formatter/html.py +++ b/pint/delegates/formatter/html.py @@ -77,7 +77,7 @@ def format_magnitude( ) m = _EXP_PATTERN.match(mstr) - _exp_formatter = lambda s: f"{s}" + _exp_formatter = lambda s: f"{s}" # noqa: E731 if m: exp = int(m.group(2) + m.group(3)) diff --git a/pint/facets/context/objects.py b/pint/facets/context/objects.py index edd1dfb2a..456dbaf6a 100644 --- a/pint/facets/context/objects.py +++ b/pint/facets/context/objects.py @@ -13,7 +13,7 @@ from collections.abc import Callable, Iterable from typing import TYPE_CHECKING, Any, Generic, Protocol -from ..._typing import Magnitude +from ..._typing import Magnitude, UnitLike from ...facets.plain import MagnitudeT, PlainQuantity, PlainUnit, UnitDefinition from ...util import UnitsContainer, to_units_container from .definitions import ContextDefinition @@ -29,8 +29,6 @@ def __call__( ... -from ..._typing import UnitLike - ToBaseFunc = Callable[[UnitsContainer], UnitsContainer] SrcDst = tuple[UnitsContainer, UnitsContainer] diff --git a/pint/facets/plain/quantity.py b/pint/facets/plain/quantity.py index 101a4c84b..15dbdf0e5 100644 --- a/pint/facets/plain/quantity.py +++ b/pint/facets/plain/quantity.py @@ -1401,10 +1401,10 @@ def compare(self, other, op): ) return op(self.to_root_units().magnitude, other.to_root_units().magnitude) - __lt__ = lambda self, other: self.compare(other, op=operator.lt) - __le__ = lambda self, other: self.compare(other, op=operator.le) - __ge__ = lambda self, other: self.compare(other, op=operator.ge) - __gt__ = lambda self, other: self.compare(other, op=operator.gt) + __lt__ = lambda self, other: self.compare(other, op=operator.lt) # noqa: E731 + __le__ = lambda self, other: self.compare(other, op=operator.le) # noqa: E731 + __ge__ = lambda self, other: self.compare(other, op=operator.ge) # noqa: E731 + __gt__ = lambda self, other: self.compare(other, op=operator.gt) # noqa: E731 def __bool__(self) -> bool: # Only cast when non-ambiguous (when multiplicative unit) diff --git a/pint/facets/plain/unit.py b/pint/facets/plain/unit.py index 0ee05abbc..8e195e401 100644 --- a/pint/facets/plain/unit.py +++ b/pint/facets/plain/unit.py @@ -218,10 +218,10 @@ def compare(self, other, op) -> bool: return NotImplemented - __lt__ = lambda self, other: self.compare(other, op=operator.lt) - __le__ = lambda self, other: self.compare(other, op=operator.le) - __ge__ = lambda self, other: self.compare(other, op=operator.ge) - __gt__ = lambda self, other: self.compare(other, op=operator.gt) + __lt__ = lambda self, other: self.compare(other, op=operator.lt) # noqa: E731 + __le__ = lambda self, other: self.compare(other, op=operator.le) # noqa: E731 + __ge__ = lambda self, other: self.compare(other, op=operator.ge) # noqa: E731 + __gt__ = lambda self, other: self.compare(other, op=operator.gt) # noqa: E731 def __int__(self) -> int: return int(self._REGISTRY.Quantity(1, self._units)) diff --git a/pint/formatting.py b/pint/formatting.py index b7a895e45..ffc7a5691 100644 --- a/pint/formatting.py +++ b/pint/formatting.py @@ -104,7 +104,7 @@ def formatter( return "" if as_ratio: - fun = lambda x: exp_call(abs(x)) + fun = lambda x: exp_call(abs(x)) # noqa: E731 else: fun = exp_call diff --git a/pint/testsuite/test_compat_downcast.py b/pint/testsuite/test_compat_downcast.py index 2fccbacab..58a247f26 100644 --- a/pint/testsuite/test_compat_downcast.py +++ b/pint/testsuite/test_compat_downcast.py @@ -169,4 +169,4 @@ def test_array_quantity_creation_by_multiplication( # This is to avoid having a ureg built at the module level. unit = unit(local_registry) - assert type(op(local_registry, array, unit)) == local_registry.Quantity + assert type(op(local_registry, array, unit)) is local_registry.Quantity diff --git a/pint/testsuite/test_converters.py b/pint/testsuite/test_converters.py index 40346c700..3b068e038 100644 --- a/pint/testsuite/test_converters.py +++ b/pint/testsuite/test_converters.py @@ -55,8 +55,8 @@ def test_log_converter(self): @helpers.requires_numpy def test_converter_inplace(self): for c in (ScaleConverter(20.0), OffsetConverter(20.0, 2)): - fun1 = lambda x, y: c.from_reference(c.to_reference(x, y), y) - fun2 = lambda x, y: c.to_reference(c.from_reference(x, y), y) + fun1 = lambda x, y: c.from_reference(c.to_reference(x, y), y)# noqa: E731 + fun2 = lambda x, y: c.to_reference(c.from_reference(x, y), y)# noqa: E731 for fun, (inplace, comp) in itertools.product( (fun1, fun2), ((True, True), (False, False)) ): @@ -74,13 +74,15 @@ def test_log_converter_inplace(self): arb_value = 3.13 c = LogarithmicConverter(scale=1, logbase=10, logfactor=1) - from_to = lambda value, inplace: c.from_reference( - c.to_reference(value, inplace), inplace - ) + def from_to(value, inplace): + return c.from_reference( + c.to_reference(value, inplace), inplace + ) - to_from = lambda value, inplace: c.to_reference( - c.from_reference(value, inplace), inplace - ) + def to_from(value, inplace): + return c.to_reference( + c.from_reference(value, inplace), inplace + ) for fun, (inplace, comp) in itertools.product( (from_to, to_from), ((True, True), (False, False)) diff --git a/pint/testsuite/test_dask.py b/pint/testsuite/test_dask.py index e52640ff4..a18280d94 100644 --- a/pint/testsuite/test_dask.py +++ b/pint/testsuite/test_dask.py @@ -12,9 +12,9 @@ dask = pytest.importorskip("dask", reason="Dask is not available") distributed = pytest.importorskip("distributed", reason="Distributed is not available") -from dask.distributed import Client -from distributed.client import futures_of -from distributed.utils_test import ( # noqa: F401 +from dask.distributed import Client # noqa: E402 +from distributed.client import futures_of # noqa: E402 +from distributed.utils_test import ( # noqa: E402, F401 cleanup, cluster, gen_cluster, @@ -151,8 +151,8 @@ def test_compute_persist_equivalent(local_registry, dask_array, numpy_array): assert np.all(res_compute == res_persist) assert res_compute.units == res_persist.units == units_ - assert type(res_compute) == local_registry.Quantity - assert type(res_persist) == local_registry.Quantity + assert type(res_compute) is local_registry.Quantity + assert type(res_persist) is local_registry.Quantity @pytest.mark.parametrize("method", ["compute", "persist", "visualize"]) diff --git a/pint/testsuite/test_diskcache.py b/pint/testsuite/test_diskcache.py index 16f3460c6..3c977e086 100644 --- a/pint/testsuite/test_diskcache.py +++ b/pint/testsuite/test_diskcache.py @@ -10,11 +10,10 @@ import pint from pint.facets.plain import UnitDefinition -FS_SLEEP = 0.010 - - from .helpers import internal +FS_SLEEP = 0.010 + @pytest.fixture def float_cache_filename(tmp_path): diff --git a/pint/testsuite/test_non_int.py b/pint/testsuite/test_non_int.py index ccf0dd6ff..d5b30f16e 100644 --- a/pint/testsuite/test_non_int.py +++ b/pint/testsuite/test_non_int.py @@ -91,7 +91,7 @@ def test_nan_creation(self): ): x = self.Q_(*args) assert math.isnan(x.magnitude) - assert type(x.magnitude) == self.kwargs["non_int_type"] + assert type(x.magnitude) is self.kwargs["non_int_type"] assert x.units == self.ureg.UnitsContainer(meter=1) else: diff --git a/pint/testsuite/test_pitheorem.py b/pint/testsuite/test_pitheorem.py index 665d5798e..6ba0e9d31 100644 --- a/pint/testsuite/test_pitheorem.py +++ b/pint/testsuite/test_pitheorem.py @@ -27,10 +27,10 @@ def test_inputs(self): T = "ms" L = "cm" - f1 = lambda x: x - f2 = lambda x: self.Q_(1, x) - f3 = lambda x: self.Q_(1, x).units - f4 = lambda x: self.Q_(1, x).dimensionality + f1 = lambda x: x # noqa: E731 + f2 = lambda x: self.Q_(1, x) # noqa: E731 + f3 = lambda x: self.Q_(1, x).units # noqa: E731 + f4 = lambda x: self.Q_(1, x).dimensionality # noqa: E731 fs = f1, f2, f3, f4 for fv, ft, fl in itertools.product(fs, fs, fs): diff --git a/pint/testsuite/test_util.py b/pint/testsuite/test_util.py index 0a6d357d0..6469dbeb3 100644 --- a/pint/testsuite/test_util.py +++ b/pint/testsuite/test_util.py @@ -159,9 +159,9 @@ def test_dict_conversion(self): class TestParseHelper: def test_basic(self): # Parse Helper ar mutables, so we build one everytime - x = lambda: ParserHelper(1, meter=2) - xp = lambda: ParserHelper(1, meter=2) - y = lambda: ParserHelper(2, meter=2) + x = lambda: ParserHelper(1, meter=2) # noqa: E731 + xp = lambda: ParserHelper(1, meter=2) # noqa: E731 + y = lambda: ParserHelper(2, meter=2) # noqa: E731 assert x() == xp() assert x() != y() @@ -179,9 +179,9 @@ def test_basic(self): def test_calculate(self): # Parse Helper ar mutables, so we build one everytime - x = lambda: ParserHelper(1.0, meter=2) - y = lambda: ParserHelper(2.0, meter=-2) - z = lambda: ParserHelper(2.0, meter=2) + x = lambda: ParserHelper(1.0, meter=2) # noqa: E731 + y = lambda: ParserHelper(2.0, meter=-2) # noqa: E731 + z = lambda: ParserHelper(2.0, meter=2) # noqa: E731 assert x() * 4.0 == ParserHelper(4.0, meter=2) assert x() * y() == ParserHelper(2.0) @@ -199,7 +199,7 @@ def _test_eval_token(self, expected, expression): token = next(pint_eval.tokenizer(expression)) actual = ParserHelper.eval_token(token) assert expected == actual - assert type(expected) == type(actual) + assert type(expected) is type(actual) def test_eval_token(self): self._test_eval_token(1000.0, "1e3") From f4c19810f9f65348f7afc8e74e6618cb4cd7e78b Mon Sep 17 00:00:00 2001 From: Mauro Silberberg Date: Tue, 18 Feb 2025 17:54:57 -0300 Subject: [PATCH 3/5] lint: ruff format --- pint/__init__.py | 16 ++-- pint/_typing.py | 3 +- pint/babel_names.py | 8 +- pint/converters.py | 10 +- pint/definitions.py | 10 +- pint/delegates/__init__.py | 11 ++- pint/delegates/base_defparser.py | 10 +- pint/delegates/formatter/__init__.py | 15 +-- .../formatter/_compound_unit_helpers.py | 11 +-- pint/delegates/formatter/_format_helpers.py | 13 ++- pint/delegates/formatter/_to_register.py | 10 +- pint/delegates/formatter/full.py | 12 +-- pint/delegates/formatter/html.py | 12 +-- pint/delegates/formatter/latex.py | 15 ++- pint/delegates/formatter/plain.py | 18 ++-- pint/delegates/txt_defparser/__init__.py | 11 ++- pint/delegates/txt_defparser/block.py | 20 ++-- pint/delegates/txt_defparser/common.py | 12 +-- pint/delegates/txt_defparser/context.py | 18 ++-- pint/delegates/txt_defparser/defaults.py | 14 +-- pint/delegates/txt_defparser/group.py | 18 ++-- pint/delegates/txt_defparser/plain.py | 40 ++++---- pint/delegates/txt_defparser/system.py | 8 +- pint/errors.py | 16 ++-- pint/facets/__init__.py | 96 +++++++++---------- pint/facets/context/__init__.py | 12 +-- pint/facets/context/definitions.py | 8 +- pint/facets/context/objects.py | 31 +++--- pint/facets/context/registry.py | 32 ++++--- pint/facets/dask/__init__.py | 11 +-- pint/facets/group/__init__.py | 10 +- pint/facets/group/definitions.py | 8 +- pint/facets/group/objects.py | 8 +- pint/facets/group/registry.py | 8 +- pint/facets/measurement/__init__.py | 10 +- pint/facets/measurement/objects.py | 8 +- pint/facets/measurement/registry.py | 9 +- pint/facets/nonmultiplicative/__init__.py | 14 +-- pint/facets/nonmultiplicative/definitions.py | 8 +- pint/facets/nonmultiplicative/objects.py | 8 +- pint/facets/nonmultiplicative/registry.py | 8 +- pint/facets/numpy/__init__.py | 10 +- pint/facets/numpy/numpy_func.py | 8 +- pint/facets/numpy/quantity.py | 8 +- pint/facets/numpy/registry.py | 9 +- pint/facets/numpy/unit.py | 8 +- pint/facets/plain/__init__.py | 10 +- pint/facets/plain/definitions.py | 8 +- pint/facets/plain/objects.py | 8 +- pint/facets/plain/qto.py | 12 +-- pint/facets/plain/quantity.py | 17 ++-- pint/facets/plain/registry.py | 40 ++++---- pint/facets/plain/unit.py | 10 +- pint/facets/system/__init__.py | 10 +- pint/facets/system/definitions.py | 8 +- pint/facets/system/objects.py | 9 +- pint/facets/system/registry.py | 8 +- pint/formatting.py | 10 +- pint/matplotlib.py | 12 +-- pint/pint_eval.py | 13 +-- pint/registry.py | 16 ++-- pint/registry_helpers.py | 10 +- pint/testing.py | 10 +- pint/testsuite/test_application_registry.py | 4 +- pint/testsuite/test_converters.py | 12 +-- pint/util.py | 10 +- 66 files changed, 444 insertions(+), 456 deletions(-) diff --git a/pint/__init__.py b/pint/__init__.py index abfef2703..a9548280c 100644 --- a/pint/__init__.py +++ b/pint/__init__.py @@ -1,14 +1,14 @@ """ - pint - ~~~~ +pint +~~~~ - Pint is Python module/package to define, operate and manipulate - **physical quantities**: the product of a numerical value and a - unit of measurement. It allows arithmetic operations between them - and conversions from and to different units. +Pint is Python module/package to define, operate and manipulate +**physical quantities**: the product of a numerical value and a +unit of measurement. It allows arithmetic operations between them +and conversions from and to different units. - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/_typing.py b/pint/_typing.py index 241459ef1..778145d6e 100644 --- a/pint/_typing.py +++ b/pint/_typing.py @@ -48,5 +48,4 @@ class Handler(Protocol): - def __getitem__(self, item: type[T]) -> Callable[[T], None]: - ... + def __getitem__(self, item: type[T]) -> Callable[[T], None]: ... diff --git a/pint/babel_names.py b/pint/babel_names.py index 408ef8f8c..a0b42d231 100644 --- a/pint/babel_names.py +++ b/pint/babel_names.py @@ -1,9 +1,9 @@ """ - pint.babel - ~~~~~~~~~~ +pint.babel +~~~~~~~~~~ - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/converters.py b/pint/converters.py index fbe3b5fb0..e80cc5bc4 100644 --- a/pint/converters.py +++ b/pint/converters.py @@ -1,11 +1,11 @@ """ - pint.converters - ~~~~~~~~~~~~~~~ +pint.converters +~~~~~~~~~~~~~~~ - Functions and classes related to unit conversions. +Functions and classes related to unit conversions. - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/definitions.py b/pint/definitions.py index da884ed95..29612f540 100644 --- a/pint/definitions.py +++ b/pint/definitions.py @@ -1,11 +1,11 @@ """ - pint.definitions - ~~~~~~~~~~~~~~~~ +pint.definitions +~~~~~~~~~~~~~~~~ - Kept for backwards compatibility +Kept for backwards compatibility - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/__init__.py b/pint/delegates/__init__.py index dc4699cf9..2870a6570 100644 --- a/pint/delegates/__init__.py +++ b/pint/delegates/__init__.py @@ -1,12 +1,13 @@ """ - pint.delegates - ~~~~~~~~~~~~~~ +pint.delegates +~~~~~~~~~~~~~~ - Defines methods and classes to handle autonomous tasks. +Defines methods and classes to handle autonomous tasks. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ + from __future__ import annotations from . import txt_defparser diff --git a/pint/delegates/base_defparser.py b/pint/delegates/base_defparser.py index 44170f842..a0caa9aa1 100644 --- a/pint/delegates/base_defparser.py +++ b/pint/delegates/base_defparser.py @@ -1,11 +1,11 @@ """ - pint.delegates.base_defparser - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.base_defparser +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Common class and function for all parsers. +Common class and function for all parsers. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/formatter/__init__.py b/pint/delegates/formatter/__init__.py index 5dab6a0f0..458189c45 100644 --- a/pint/delegates/formatter/__init__.py +++ b/pint/delegates/formatter/__init__.py @@ -1,15 +1,16 @@ """ - pint.delegates.formatter - ~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter +~~~~~~~~~~~~~~~~~~~~~~~~ - Easy to replace and extend string formatting. +Easy to replace and extend string formatting. - See pint.delegates.formatter.plain.DefaultFormatter for a - description of a formatter. +See pint.delegates.formatter.plain.DefaultFormatter for a +description of a formatter. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ + from __future__ import annotations from .full import FullFormatter diff --git a/pint/delegates/formatter/_compound_unit_helpers.py b/pint/delegates/formatter/_compound_unit_helpers.py index 06a8ac2d3..78abffb99 100644 --- a/pint/delegates/formatter/_compound_unit_helpers.py +++ b/pint/delegates/formatter/_compound_unit_helpers.py @@ -1,14 +1,13 @@ """ - pint.delegates.formatter._compound_unit_helpers - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter._compound_unit_helpers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Convenient functions to help organize compount units. +Convenient functions to help organize compount units. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations import functools diff --git a/pint/delegates/formatter/_format_helpers.py b/pint/delegates/formatter/_format_helpers.py index da1c1f7f2..d53876be3 100644 --- a/pint/delegates/formatter/_format_helpers.py +++ b/pint/delegates/formatter/_format_helpers.py @@ -1,14 +1,13 @@ """ - pint.delegates.formatter._format_helpers - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter._format_helpers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Convenient functions to help string formatting operations. +Convenient functions to help string formatting operations. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations import re @@ -101,7 +100,7 @@ def override_locale( def pretty_fmt_exponent(num: Number) -> str: """Format an number into a pretty printed exponent.""" # unicode dot operator (U+22C5) looks like a superscript decimal - ret = f"{num:n}".replace("-", "⁻").replace(".", "\u22C5") + ret = f"{num:n}".replace("-", "⁻").replace(".", "\u22c5") for n in range(10): ret = ret.replace(str(n), _PRETTY_EXPONENTS[n]) return ret diff --git a/pint/delegates/formatter/_to_register.py b/pint/delegates/formatter/_to_register.py index d808640d6..896333264 100644 --- a/pint/delegates/formatter/_to_register.py +++ b/pint/delegates/formatter/_to_register.py @@ -1,9 +1,9 @@ """ - pint.delegates.formatter.base_formatter - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Common class and function for all formatters. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +pint.delegates.formatter.base_formatter +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Common class and function for all formatters. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/formatter/full.py b/pint/delegates/formatter/full.py index 3b5804439..bdf2da12a 100644 --- a/pint/delegates/formatter/full.py +++ b/pint/delegates/formatter/full.py @@ -1,12 +1,12 @@ """ - pint.delegates.formatter.full - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter.full +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Implements: - - Full: dispatch to other formats, accept defaults. +Implements: +- Full: dispatch to other formats, accept defaults. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/formatter/html.py b/pint/delegates/formatter/html.py index 2a751cd45..8bc7bfc9d 100644 --- a/pint/delegates/formatter/html.py +++ b/pint/delegates/formatter/html.py @@ -1,12 +1,12 @@ """ - pint.delegates.formatter.html - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter.html +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Implements: - - HTML: suitable for web/jupyter notebook outputs. +Implements: +- HTML: suitable for web/jupyter notebook outputs. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/formatter/latex.py b/pint/delegates/formatter/latex.py index 468a65fa4..5fe0a5240 100644 --- a/pint/delegates/formatter/latex.py +++ b/pint/delegates/formatter/latex.py @@ -1,16 +1,15 @@ """ - pint.delegates.formatter.latex - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter.latex +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Implements: - - Latex: uses vainilla latex. - - SIunitx: uses latex siunitx package format. +Implements: +- Latex: uses vainilla latex. +- SIunitx: uses latex siunitx package format. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations import functools diff --git a/pint/delegates/formatter/plain.py b/pint/delegates/formatter/plain.py index 744cbb402..c54aacc95 100644 --- a/pint/delegates/formatter/plain.py +++ b/pint/delegates/formatter/plain.py @@ -1,15 +1,15 @@ """ - pint.delegates.formatter.plain - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.formatter.plain +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Implements plain text formatters: - - Raw: as simple as it gets (no locale aware, no unit formatter.) - - Default: used when no string spec is given. - - Compact: like default but with less spaces. - - Pretty: pretty printed formatter. +Implements plain text formatters: +- Raw: as simple as it gets (no locale aware, no unit formatter.) +- Default: used when no string spec is given. +- Compact: like default but with less spaces. +- Pretty: pretty printed formatter. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/txt_defparser/__init__.py b/pint/delegates/txt_defparser/__init__.py index ba0dbbf65..0f4ebbb65 100644 --- a/pint/delegates/txt_defparser/__init__.py +++ b/pint/delegates/txt_defparser/__init__.py @@ -1,12 +1,13 @@ """ - pint.delegates.txt_defparser - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Parser for the original textual Pint Definition file. +Parser for the original textual Pint Definition file. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ + from __future__ import annotations from .defparser import DefParser diff --git a/pint/delegates/txt_defparser/block.py b/pint/delegates/txt_defparser/block.py index 6e8d18968..2c4ff8e11 100644 --- a/pint/delegates/txt_defparser/block.py +++ b/pint/delegates/txt_defparser/block.py @@ -1,18 +1,17 @@ """ - pint.delegates.txt_defparser.block - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser.block +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Classes for Pint Blocks, which are defined by: +Classes for Pint Blocks, which are defined by: - @ - - @end + @ + + @end - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations from dataclasses import dataclass @@ -50,5 +49,4 @@ class DirectiveBlock( Subclass this class for convenience. """ - def derive_definition(self) -> DefT: - ... + def derive_definition(self) -> DefT: ... diff --git a/pint/delegates/txt_defparser/common.py b/pint/delegates/txt_defparser/common.py index def901d88..bb2b40201 100644 --- a/pint/delegates/txt_defparser/common.py +++ b/pint/delegates/txt_defparser/common.py @@ -1,13 +1,13 @@ """ - pint.delegates.txt_defparser.common - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser.common +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Definitions for parsing an Import Statement +Definitions for parsing an Import Statement - Also DefinitionSyntaxError +Also DefinitionSyntaxError - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/txt_defparser/context.py b/pint/delegates/txt_defparser/context.py index 029b60445..be5fb85b7 100644 --- a/pint/delegates/txt_defparser/context.py +++ b/pint/delegates/txt_defparser/context.py @@ -1,17 +1,17 @@ """ - pint.delegates.txt_defparser.context - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser.context +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Definitions for parsing Context and their related objects +Definitions for parsing Context and their related objects - Notices that some of the checks are done within the - format agnostic parent definition class. +Notices that some of the checks are done within the +format agnostic parent definition class. - See each one for a slighly longer description of the - syntax. +See each one for a slighly longer description of the +syntax. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/txt_defparser/defaults.py b/pint/delegates/txt_defparser/defaults.py index 669daddb4..a6b9c5bf0 100644 --- a/pint/delegates/txt_defparser/defaults.py +++ b/pint/delegates/txt_defparser/defaults.py @@ -1,14 +1,14 @@ """ - pint.delegates.txt_defparser.defaults - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser.defaults +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Definitions for parsing Default sections. +Definitions for parsing Default sections. - See each one for a slighly longer description of the - syntax. +See each one for a slighly longer description of the +syntax. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/txt_defparser/group.py b/pint/delegates/txt_defparser/group.py index 120438a83..32d1e6c80 100644 --- a/pint/delegates/txt_defparser/group.py +++ b/pint/delegates/txt_defparser/group.py @@ -1,17 +1,17 @@ """ - pint.delegates.txt_defparser.group - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser.group +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Definitions for parsing Group and their related objects +Definitions for parsing Group and their related objects - Notices that some of the checks are done within the - format agnostic parent definition class. +Notices that some of the checks are done within the +format agnostic parent definition class. - See each one for a slighly longer description of the - syntax. +See each one for a slighly longer description of the +syntax. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/txt_defparser/plain.py b/pint/delegates/txt_defparser/plain.py index ac4230bcb..174a30d09 100644 --- a/pint/delegates/txt_defparser/plain.py +++ b/pint/delegates/txt_defparser/plain.py @@ -1,24 +1,24 @@ """ - pint.delegates.txt_defparser.plain - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Definitions for parsing: - - Equality - - CommentDefinition - - PrefixDefinition - - UnitDefinition - - DimensionDefinition - - DerivedDimensionDefinition - - AliasDefinition - - Notices that some of the checks are done within the - format agnostic parent definition class. - - See each one for a slighly longer description of the - syntax. - - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +pint.delegates.txt_defparser.plain +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Definitions for parsing: +- Equality +- CommentDefinition +- PrefixDefinition +- UnitDefinition +- DimensionDefinition +- DerivedDimensionDefinition +- AliasDefinition + +Notices that some of the checks are done within the +format agnostic parent definition class. + +See each one for a slighly longer description of the +syntax. + +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/delegates/txt_defparser/system.py b/pint/delegates/txt_defparser/system.py index 8c45b0b0b..5ffa759f4 100644 --- a/pint/delegates/txt_defparser/system.py +++ b/pint/delegates/txt_defparser/system.py @@ -1,9 +1,9 @@ """ - pint.delegates.txt_defparser.system - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.delegates.txt_defparser.system +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/errors.py b/pint/errors.py index d1882dbdd..f5b6f9d7b 100644 --- a/pint/errors.py +++ b/pint/errors.py @@ -1,11 +1,11 @@ """ - pint.errors - ~~~~~~~~~~~ +pint.errors +~~~~~~~~~~~ - Functions and classes related to unit definitions and conversions. +Functions and classes related to unit definitions and conversions. - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations @@ -55,9 +55,9 @@ def _no_space(name: str) -> bool: is_valid_group_name = _no_space -is_valid_unit_alias = ( - is_valid_prefix_alias -) = is_valid_unit_symbol = is_valid_prefix_symbol = _no_space +is_valid_unit_alias = is_valid_prefix_alias = is_valid_unit_symbol = ( + is_valid_prefix_symbol +) = _no_space def is_valid_dimension_name(name: str) -> bool: diff --git a/pint/facets/__init__.py b/pint/facets/__init__.py index 12729289c..34a60e4a4 100644 --- a/pint/facets/__init__.py +++ b/pint/facets/__init__.py @@ -1,70 +1,70 @@ """ - pint.facets - ~~~~~~~~~~~ +pint.facets +~~~~~~~~~~~ - Facets are way to add a specific set of funcionalities to Pint. It is more - an organization logic than anything else. It aims to enable growth while - keeping each part small enough to be hackable. +Facets are way to add a specific set of funcionalities to Pint. It is more +an organization logic than anything else. It aims to enable growth while +keeping each part small enough to be hackable. - Each facet contains one or more of the following modules: - - definitions: classes describing specific unit-related definitons. - These objects must be immutable, pickable and not reference the registry (e.g. ContextDefinition) - - objects: classes and functions that encapsulate behavior (e.g. Context) - - registry: implements a subclass of PlainRegistry or class that can be - mixed with it (e.g. ContextRegistry) +Each facet contains one or more of the following modules: +- definitions: classes describing specific unit-related definitons. + These objects must be immutable, pickable and not reference the registry (e.g. ContextDefinition) +- objects: classes and functions that encapsulate behavior (e.g. Context) +- registry: implements a subclass of PlainRegistry or class that can be + mixed with it (e.g. ContextRegistry) - In certain cases, some of these modules might be collapsed into a single one - as the code is very short (like in dask) or expanded as the code is too long - (like in plain, where quantity and unit object are in their own module). - Additionally, certain facets might not have one of them. +In certain cases, some of these modules might be collapsed into a single one +as the code is very short (like in dask) or expanded as the code is too long +(like in plain, where quantity and unit object are in their own module). +Additionally, certain facets might not have one of them. - An important part of this scheme is that each facet should export only a few - classes in the __init__.py and everything else should not be accessed by any - other module (except for testing). This is Python, so accessing it cannot be - really limited. So is more an agreement than a rule. +An important part of this scheme is that each facet should export only a few +classes in the __init__.py and everything else should not be accessed by any +other module (except for testing). This is Python, so accessing it cannot be +really limited. So is more an agreement than a rule. - It is worth noticing that a Pint Quantity or Unit is always connected to a - *specific* registry. Therefore we need to provide a way in which functionality - can be added to a Quantity class in an easy way. This is achieved beautifully - using specific class attributes. For example, the NumpyRegistry looks like this: +It is worth noticing that a Pint Quantity or Unit is always connected to a +*specific* registry. Therefore we need to provide a way in which functionality +can be added to a Quantity class in an easy way. This is achieved beautifully +using specific class attributes. For example, the NumpyRegistry looks like this: - class NumpyRegistry: +class NumpyRegistry: - Quantity = NumpyQuantity - Unit = NumpyUnit + Quantity = NumpyQuantity + Unit = NumpyUnit - This tells pint that it should use NumpyQuantity as base class for a quantity - class that belongs to a registry that has NumpyRegistry as one of its bases. +This tells pint that it should use NumpyQuantity as base class for a quantity +class that belongs to a registry that has NumpyRegistry as one of its bases. - Currently the folowing facets are implemented: +Currently the folowing facets are implemented: - - plain: basic manipulation and calculation with multiplicative - dimensions, units and quantities (e.g. length, time, mass, etc). +- plain: basic manipulation and calculation with multiplicative + dimensions, units and quantities (e.g. length, time, mass, etc). - - nonmultiplicative: manipulation and calculation with offset and - log units and quantities (e.g. temperature and decibel). +- nonmultiplicative: manipulation and calculation with offset and + log units and quantities (e.g. temperature and decibel). - - measurement: manipulation and calculation of a quantity with - an uncertainty. +- measurement: manipulation and calculation of a quantity with + an uncertainty. - - numpy: using numpy array as magnitude and properly handling - numpy functions operating on quantities. +- numpy: using numpy array as magnitude and properly handling + numpy functions operating on quantities. - - dask: allows pint to interoperate with dask by implementing - dask magic methods. +- dask: allows pint to interoperate with dask by implementing + dask magic methods. - - group: allow to make collections of units that can be then - addressed together. +- group: allow to make collections of units that can be then + addressed together. - - system: redefine base units for dimensions for a particular - collection of units (e.g. imperial) +- system: redefine base units for dimensions for a particular + collection of units (e.g. imperial) - - context: provides the means to interconvert between incompatible - units through well defined relations (e.g. spectroscopy allows - converting between spatial wavelength and temporal frequency) +- context: provides the means to interconvert between incompatible + units through well defined relations (e.g. spectroscopy allows + converting between spatial wavelength and temporal frequency) - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/context/__init__.py b/pint/facets/context/__init__.py index 28c7b5ced..0514b82e1 100644 --- a/pint/facets/context/__init__.py +++ b/pint/facets/context/__init__.py @@ -1,12 +1,12 @@ """ - pint.facets.context - ~~~~~~~~~~~~~~~~~~~ +pint.facets.context +~~~~~~~~~~~~~~~~~~~ - Adds pint the capability to contexts: predefined conversions - between incompatible dimensions. +Adds pint the capability to contexts: predefined conversions +between incompatible dimensions. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/context/definitions.py b/pint/facets/context/definitions.py index 76f84d63d..503a994e7 100644 --- a/pint/facets/context/definitions.py +++ b/pint/facets/context/definitions.py @@ -1,9 +1,9 @@ """ - pint.facets.context.definitions - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.context.definitions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/context/objects.py b/pint/facets/context/objects.py index 456dbaf6a..a5f04bcbd 100644 --- a/pint/facets/context/objects.py +++ b/pint/facets/context/objects.py @@ -1,9 +1,9 @@ """ - pint.facets.context.objects - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.context.objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations @@ -25,8 +25,7 @@ class Transformation(Protocol): def __call__( self, ureg: UnitRegistry, value: PlainQuantity, **kwargs: Any - ) -> PlainQuantity: - ... + ) -> PlainQuantity: ... ToBaseFunc = Callable[[UnitsContainer], UnitsContainer] @@ -73,19 +72,19 @@ class Context: >>> from pint.util import UnitsContainer >>> from pint import Context, UnitRegistry >>> ureg = UnitRegistry() - >>> timedim = UnitsContainer({'[time]': 1}) - >>> spacedim = UnitsContainer({'[length]': 1}) + >>> timedim = UnitsContainer({"[time]": 1}) + >>> spacedim = UnitsContainer({"[length]": 1}) >>> def time_to_len(ureg, time): - ... 'Time to length converter' - ... return 3. * time + ... "Time to length converter" + ... return 3.0 * time >>> c = Context() >>> c.add_transformation(timedim, spacedim, time_to_len) >>> c.transform(timedim, spacedim, ureg, 2) 6.0 >>> def time_to_len_indexed(ureg, time, n=1): - ... 'Time to length converter, n is the index of refraction of the material' - ... return 3. * time / n - >>> c = Context(defaults={'n':3}) + ... "Time to length converter, n is the index of refraction of the material" + ... return 3.0 * time / n + >>> c = Context(defaults={"n": 3}) >>> c.add_transformation(timedim, spacedim, time_to_len_indexed) >>> c.transform(timedim, spacedim, ureg, 2) 2.0 @@ -116,9 +115,9 @@ def __init__( #: Maps (src, dst) -> self #: Used as a convenience dictionary to be composed by ContextChain - self.relation_to_context: weakref.WeakValueDictionary[ - SrcDst, Context - ] = weakref.WeakValueDictionary() + self.relation_to_context: weakref.WeakValueDictionary[SrcDst, Context] = ( + weakref.WeakValueDictionary() + ) @classmethod def from_context(cls, context: Context, **defaults: Any) -> Context: diff --git a/pint/facets/context/registry.py b/pint/facets/context/registry.py index c91f289b8..b8cd4aace 100644 --- a/pint/facets/context/registry.py +++ b/pint/facets/context/registry.py @@ -1,9 +1,9 @@ """ - pint.facets.context.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.context.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations @@ -276,32 +276,32 @@ def context( >>> import pint.facets.context.objects >>> import pint >>> ureg = pint.UnitRegistry() - >>> ureg.add_context(pint.facets.context.objects.Context('one')) - >>> ureg.add_context(pint.facets.context.objects.Context('two')) - >>> with ureg.context('one'): + >>> ureg.add_context(pint.facets.context.objects.Context("one")) + >>> ureg.add_context(pint.facets.context.objects.Context("two")) + >>> with ureg.context("one"): ... pass If a context has an argument, you can specify its value as a keyword argument: - >>> with ureg.context('one', n=1): + >>> with ureg.context("one", n=1): ... pass Multiple contexts can be entered in single call: - >>> with ureg.context('one', 'two', n=1): + >>> with ureg.context("one", "two", n=1): ... pass Or nested allowing you to give different values to the same keyword argument: - >>> with ureg.context('one', n=1): - ... with ureg.context('two', n=2): + >>> with ureg.context("one", n=1): + ... with ureg.context("two", n=2): ... pass A nested context inherits the defaults from the containing context: - >>> with ureg.context('one', n=1): + >>> with ureg.context("one", n=1): ... # Here n takes the value of the outer context - ... with ureg.context('two'): + ... with ureg.context("two"): ... pass """ # Enable the contexts. @@ -336,9 +336,11 @@ def with_context(self, name: str, **kwargs: Any) -> Callable[[F], F]: Examples -------- - >>> @ureg.with_context('sp') + >>> @ureg.with_context("sp") ... def my_cool_fun(wavelength): - ... print('This wavelength is equivalent to: %s', wavelength.to('terahertz')) + ... print( + ... "This wavelength is equivalent to: %s", wavelength.to("terahertz") + ... ) """ def decorator(func): diff --git a/pint/facets/dask/__init__.py b/pint/facets/dask/__init__.py index c3133bc31..2bd08b84f 100644 --- a/pint/facets/dask/__init__.py +++ b/pint/facets/dask/__init__.py @@ -1,14 +1,13 @@ """ - pint.facets.dask - ~~~~~~~~~~~~~~~~ +pint.facets.dask +~~~~~~~~~~~~~~~~ - Adds pint the capability to interoperate with Dask +Adds pint the capability to interoperate with Dask - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations import functools diff --git a/pint/facets/group/__init__.py b/pint/facets/group/__init__.py index db488deac..b961b4781 100644 --- a/pint/facets/group/__init__.py +++ b/pint/facets/group/__init__.py @@ -1,11 +1,11 @@ """ - pint.facets.group - ~~~~~~~~~~~~~~~~~ +pint.facets.group +~~~~~~~~~~~~~~~~~ - Adds pint the capability to group units. +Adds pint the capability to group units. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/group/definitions.py b/pint/facets/group/definitions.py index bec7d8ac0..dabc6b303 100644 --- a/pint/facets/group/definitions.py +++ b/pint/facets/group/definitions.py @@ -1,9 +1,9 @@ """ - pint.facets.group.definitions - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.group.definitions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/group/objects.py b/pint/facets/group/objects.py index a1767e666..a41e077f2 100644 --- a/pint/facets/group/objects.py +++ b/pint/facets/group/objects.py @@ -1,9 +1,9 @@ """ - pint.facets.group.objects - ~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.group.objects +~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/group/registry.py b/pint/facets/group/registry.py index 33f78c645..f3bfea0e0 100644 --- a/pint/facets/group/registry.py +++ b/pint/facets/group/registry.py @@ -1,9 +1,9 @@ """ - pint.facets.group.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.group.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/measurement/__init__.py b/pint/facets/measurement/__init__.py index 0b241ea1d..e829a8f44 100644 --- a/pint/facets/measurement/__init__.py +++ b/pint/facets/measurement/__init__.py @@ -1,11 +1,11 @@ """ - pint.facets.measurement - ~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.measurement +~~~~~~~~~~~~~~~~~~~~~~~ - Adds pint the capability to handle measurements (quantities with uncertainties). +Adds pint the capability to handle measurements (quantities with uncertainties). - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/measurement/objects.py b/pint/facets/measurement/objects.py index 4240a91d2..2ffb9ef27 100644 --- a/pint/facets/measurement/objects.py +++ b/pint/facets/measurement/objects.py @@ -1,9 +1,9 @@ """ - pint.facets.measurement.objects - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.measurement.objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/measurement/registry.py b/pint/facets/measurement/registry.py index 905de7ab7..721b5ffcb 100644 --- a/pint/facets/measurement/registry.py +++ b/pint/facets/measurement/registry.py @@ -1,12 +1,11 @@ """ - pint.facets.measurement.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.measurement.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations from typing import Any, Generic diff --git a/pint/facets/nonmultiplicative/__init__.py b/pint/facets/nonmultiplicative/__init__.py index a338dc34a..63b483bb7 100644 --- a/pint/facets/nonmultiplicative/__init__.py +++ b/pint/facets/nonmultiplicative/__init__.py @@ -1,13 +1,13 @@ """ - pint.facets.nonmultiplicative - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.nonmultiplicative +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Adds pint the capability to handle nonmultiplicative units: - - offset - - logarithmic +Adds pint the capability to handle nonmultiplicative units: +- offset +- logarithmic - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/nonmultiplicative/definitions.py b/pint/facets/nonmultiplicative/definitions.py index f795cf046..f419df831 100644 --- a/pint/facets/nonmultiplicative/definitions.py +++ b/pint/facets/nonmultiplicative/definitions.py @@ -1,9 +1,9 @@ """ - pint.facets.nonmultiplicative.definitions - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.nonmultiplicative.definitions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/nonmultiplicative/objects.py b/pint/facets/nonmultiplicative/objects.py index 114a256af..229b32c5f 100644 --- a/pint/facets/nonmultiplicative/objects.py +++ b/pint/facets/nonmultiplicative/objects.py @@ -1,9 +1,9 @@ """ - pint.facets.nonmultiplicative.objects - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.nonmultiplicative.objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/nonmultiplicative/registry.py b/pint/facets/nonmultiplicative/registry.py index 7f58d060c..f74294eaa 100644 --- a/pint/facets/nonmultiplicative/registry.py +++ b/pint/facets/nonmultiplicative/registry.py @@ -1,9 +1,9 @@ """ - pint.facets.nonmultiplicative.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.nonmultiplicative.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/numpy/__init__.py b/pint/facets/numpy/__init__.py index 477c09579..85381646d 100644 --- a/pint/facets/numpy/__init__.py +++ b/pint/facets/numpy/__init__.py @@ -1,11 +1,11 @@ """ - pint.facets.numpy - ~~~~~~~~~~~~~~~~~ +pint.facets.numpy +~~~~~~~~~~~~~~~~~ - Adds pint the capability to interoperate with NumPy +Adds pint the capability to interoperate with NumPy - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index b79700f9f..143675a20 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -1,9 +1,9 @@ """ - pint.facets.numpy.numpy_func - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.numpy.numpy_func +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/numpy/quantity.py b/pint/facets/numpy/quantity.py index 75dccec54..2d542c532 100644 --- a/pint/facets/numpy/quantity.py +++ b/pint/facets/numpy/quantity.py @@ -1,9 +1,9 @@ """ - pint.facets.numpy.quantity - ~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.numpy.quantity +~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/numpy/registry.py b/pint/facets/numpy/registry.py index e1128f383..38fc045a4 100644 --- a/pint/facets/numpy/registry.py +++ b/pint/facets/numpy/registry.py @@ -1,12 +1,11 @@ """ - pint.facets.numpy.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.numpy.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations from typing import Any, Generic diff --git a/pint/facets/numpy/unit.py b/pint/facets/numpy/unit.py index d6bf140a2..b06424c20 100644 --- a/pint/facets/numpy/unit.py +++ b/pint/facets/numpy/unit.py @@ -1,9 +1,9 @@ """ - pint.facets.numpy.unit - ~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.numpy.unit +~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/plain/__init__.py b/pint/facets/plain/__init__.py index f84dd68f3..2fb72736c 100644 --- a/pint/facets/plain/__init__.py +++ b/pint/facets/plain/__init__.py @@ -1,11 +1,11 @@ """ - pint.facets.plain - ~~~~~~~~~~~~~~~~~ +pint.facets.plain +~~~~~~~~~~~~~~~~~ - Base implementation for registry, units and quantities. +Base implementation for registry, units and quantities. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/plain/definitions.py b/pint/facets/plain/definitions.py index a43ce0dbc..69d086fdb 100644 --- a/pint/facets/plain/definitions.py +++ b/pint/facets/plain/definitions.py @@ -1,9 +1,9 @@ """ - pint.facets.plain.definitions - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.plain.definitions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/plain/objects.py b/pint/facets/plain/objects.py index a868c7f95..c84cdf411 100644 --- a/pint/facets/plain/objects.py +++ b/pint/facets/plain/objects.py @@ -1,9 +1,9 @@ """ - pint.facets.plain.objects - ~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.plain.objects +~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/plain/qto.py b/pint/facets/plain/qto.py index 9d8b7f611..e178a34c8 100644 --- a/pint/facets/plain/qto.py +++ b/pint/facets/plain/qto.py @@ -94,9 +94,9 @@ def to_compact( >>> import pint >>> ureg = pint.UnitRegistry() - >>> (200e-9*ureg.s).to_compact() + >>> (200e-9 * ureg.s).to_compact() - >>> (1e-2*ureg('kg m/s^2')).to_compact('N') + >>> (1e-2 * ureg("kg m/s^2")).to_compact("N") """ @@ -181,9 +181,9 @@ def to_preferred( >>> import pint >>> ureg = pint.UnitRegistry() - >>> (1*ureg.acre).to_preferred([ureg.meters]) + >>> (1 * ureg.acre).to_preferred([ureg.meters]) - >>> (1*(ureg.force_pound*ureg.m)).to_preferred([ureg.W]) + >>> (1 * (ureg.force_pound * ureg.m)).to_preferred([ureg.W]) """ @@ -201,9 +201,9 @@ def ito_preferred( >>> import pint >>> ureg = pint.UnitRegistry() - >>> (1*ureg.acre).to_preferred([ureg.meters]) + >>> (1 * ureg.acre).to_preferred([ureg.meters]) - >>> (1*(ureg.force_pound*ureg.m)).to_preferred([ureg.W]) + >>> (1 * (ureg.force_pound * ureg.m)).to_preferred([ureg.W]) """ diff --git a/pint/facets/plain/quantity.py b/pint/facets/plain/quantity.py index 15dbdf0e5..eb0a9b1e6 100644 --- a/pint/facets/plain/quantity.py +++ b/pint/facets/plain/quantity.py @@ -166,24 +166,22 @@ def __reduce__(self) -> tuple[type, Magnitude, UnitsContainer]: @overload def __new__( cls, value: MagnitudeT, units: UnitLike | None = None - ) -> PlainQuantity[MagnitudeT]: - ... + ) -> PlainQuantity[MagnitudeT]: ... @overload - def __new__(cls, value: str, units: UnitLike | None = None) -> PlainQuantity[Any]: - ... + def __new__( + cls, value: str, units: UnitLike | None = None + ) -> PlainQuantity[Any]: ... @overload def __new__( # type: ignore[misc] cls, value: Sequence[ScalarT], units: UnitLike | None = None - ) -> PlainQuantity[Any]: - ... + ) -> PlainQuantity[Any]: ... @overload def __new__( cls, value: PlainQuantity[Any], units: UnitLike | None = None - ) -> PlainQuantity[Any]: - ... + ) -> PlainQuantity[Any]: ... def __new__(cls, value, units=None): if is_upcast_type(type(value)): @@ -831,8 +829,7 @@ def __iadd__(self, other: datetime.datetime) -> datetime.timedelta: # type: ign ... @overload - def __iadd__(self, other) -> PlainQuantity[MagnitudeT]: - ... + def __iadd__(self, other) -> PlainQuantity[MagnitudeT]: ... def __iadd__(self, other): if isinstance(other, datetime.datetime): diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index 482992f31..113d17c9b 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -1,23 +1,23 @@ """ - pint.facets.plain.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. - - The registry contains the following important methods: - - - parse_unit_name: Parse a unit to identify prefix, unit name and suffix - by walking the list of prefix and suffix. - Result is cached: NO - - parse_units: Parse a units expression and returns a UnitContainer with - the canonical names. - The expression can only contain products, ratios and powers of units; - prefixed units and pluralized units. - Result is cached: YES - - parse_expression: Parse a mathematical expression including units and - return a quantity object. - Result is cached: NO +pint.facets.plain.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. + +The registry contains the following important methods: + +- parse_unit_name: Parse a unit to identify prefix, unit name and suffix + by walking the list of prefix and suffix. + Result is cached: NO +- parse_units: Parse a units expression and returns a UnitContainer with + the canonical names. + The expression can only contain products, ratios and powers of units; + prefixed units and pluralized units. + Result is cached: YES +- parse_expression: Parse a mathematical expression including units and + return a quantity object. + Result is cached: NO """ @@ -493,7 +493,7 @@ def _helper_dispatch_adder(self, definition: Any) -> None: break else: raise TypeError( - f"No loader function defined " f"for {definition.__class__.__name__}" + f"No loader function defined for {definition.__class__.__name__}" ) adder_func(definition) diff --git a/pint/facets/plain/unit.py b/pint/facets/plain/unit.py index 8e195e401..0f9e57d7b 100644 --- a/pint/facets/plain/unit.py +++ b/pint/facets/plain/unit.py @@ -1,9 +1,9 @@ """ - pint.facets.plain.unit - ~~~~~~~~~~~~~~~~~~~~~ +pint.facets.plain.unit +~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations @@ -43,7 +43,7 @@ def __init__(self, units: UnitLike) -> None: self._units = units._units else: raise TypeError( - "units must be of type str, Unit or " "UnitsContainer; not {}.".format( + "units must be of type str, Unit or UnitsContainer; not {}.".format( type(units) ) ) diff --git a/pint/facets/system/__init__.py b/pint/facets/system/__init__.py index b9cbc9593..e73c264a1 100644 --- a/pint/facets/system/__init__.py +++ b/pint/facets/system/__init__.py @@ -1,11 +1,11 @@ """ - pint.facets.system - ~~~~~~~~~~~~~~~~~~ +pint.facets.system +~~~~~~~~~~~~~~~~~~ - Adds pint the capability to system of units. +Adds pint the capability to system of units. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/system/definitions.py b/pint/facets/system/definitions.py index f47a23fd8..e3bce4465 100644 --- a/pint/facets/system/definitions.py +++ b/pint/facets/system/definitions.py @@ -1,9 +1,9 @@ """ - pint.facets.systems.definitions - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.systems.definitions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/facets/system/objects.py b/pint/facets/system/objects.py index 751a66abf..4254958d4 100644 --- a/pint/facets/system/objects.py +++ b/pint/facets/system/objects.py @@ -1,12 +1,11 @@ """ - pint.facets.systems.objects - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.systems.objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ - from __future__ import annotations import numbers diff --git a/pint/facets/system/registry.py b/pint/facets/system/registry.py index e5235a4cb..cc0e41f1d 100644 --- a/pint/facets/system/registry.py +++ b/pint/facets/system/registry.py @@ -1,9 +1,9 @@ """ - pint.facets.systems.registry - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pint.facets.systems.registry +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/formatting.py b/pint/formatting.py index ffc7a5691..8bd2f01ce 100644 --- a/pint/formatting.py +++ b/pint/formatting.py @@ -1,11 +1,11 @@ """ - pint.formatter - ~~~~~~~~~~~~~~ +pint.formatter +~~~~~~~~~~~~~~ - Format units for pint. +Format units for pint. - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/matplotlib.py b/pint/matplotlib.py index 2ca43fa33..c0fc99e74 100644 --- a/pint/matplotlib.py +++ b/pint/matplotlib.py @@ -1,12 +1,12 @@ """ - pint.matplotlib - ~~~~~~~~~~~~~~~ +pint.matplotlib +~~~~~~~~~~~~~~~ - Functions and classes related to working with Matplotlib's support - for plotting with units. +Functions and classes related to working with Matplotlib's support +for plotting with units. - :copyright: 2017 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2017 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/pint_eval.py b/pint/pint_eval.py index 8c5f30e31..242cddb73 100644 --- a/pint/pint_eval.py +++ b/pint/pint_eval.py @@ -1,12 +1,13 @@ """ - pint.pint_eval - ~~~~~~~~~~~~~~ +pint.pint_eval +~~~~~~~~~~~~~~ - An expression evaluator to be used as a safe replacement for builtin eval. +An expression evaluator to be used as a safe replacement for builtin eval. - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ + from __future__ import annotations import operator @@ -165,7 +166,7 @@ def _get_possible_e( end = toklist.lookahead(e_index + 2).end possible_e = tokenize.TokenInfo( type=tokenlib.STRING, - string=f"e{toklist.lookahead(e_index+1).string}{exp_number}", + string=f"e{toklist.lookahead(e_index + 1).string}{exp_number}", start=possible_e_token.start, end=end, line=possible_e_token.line, diff --git a/pint/registry.py b/pint/registry.py index ceb9b62d1..9da19de67 100644 --- a/pint/registry.py +++ b/pint/registry.py @@ -1,15 +1,15 @@ """ - pint.registry - ~~~~~~~~~~~~~ +pint.registry +~~~~~~~~~~~~~ - Defines the UnitRegistry, a class to contain units and their relations. +Defines the UnitRegistry, a class to contain units and their relations. - This registry contains all pint capabilities, but you can build your - customized registry by picking only the features that you actually - need. +This registry contains all pint capabilities, but you can build your +customized registry by picking only the features that you actually +need. - :copyright: 2022 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2022 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/registry_helpers.py b/pint/registry_helpers.py index f2961cc74..14a54d20b 100644 --- a/pint/registry_helpers.py +++ b/pint/registry_helpers.py @@ -1,11 +1,11 @@ """ - pint.registry_helpers - ~~~~~~~~~~~~~~~~~~~~~ +pint.registry_helpers +~~~~~~~~~~~~~~~~~~~~~ - Miscellaneous methods of the registry written as separate functions. +Miscellaneous methods of the registry written as separate functions. - :copyright: 2016 by Pint Authors, see AUTHORS for more details.. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details.. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/testing.py b/pint/testing.py index b1da02935..c41be784d 100644 --- a/pint/testing.py +++ b/pint/testing.py @@ -1,11 +1,11 @@ """ - pint.testing - ~~~~~~~~~~~~ +pint.testing +~~~~~~~~~~~~ - Functions for testing whether pint quantities are equal. +Functions for testing whether pint quantities are equal. - :copyright: 2016 by Pint Authors, see AUTHORS for more details.. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details.. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations diff --git a/pint/testsuite/test_application_registry.py b/pint/testsuite/test_application_registry.py index 477e9f650..72336bfe9 100644 --- a/pint/testsuite/test_application_registry.py +++ b/pint/testsuite/test_application_registry.py @@ -1,5 +1,5 @@ -"""Tests for global UnitRegistry, Unit, and Quantity -""" +"""Tests for global UnitRegistry, Unit, and Quantity""" + from __future__ import annotations import pickle diff --git a/pint/testsuite/test_converters.py b/pint/testsuite/test_converters.py index 3b068e038..c5e19e927 100644 --- a/pint/testsuite/test_converters.py +++ b/pint/testsuite/test_converters.py @@ -55,8 +55,8 @@ def test_log_converter(self): @helpers.requires_numpy def test_converter_inplace(self): for c in (ScaleConverter(20.0), OffsetConverter(20.0, 2)): - fun1 = lambda x, y: c.from_reference(c.to_reference(x, y), y)# noqa: E731 - fun2 = lambda x, y: c.to_reference(c.from_reference(x, y), y)# noqa: E731 + fun1 = lambda x, y: c.from_reference(c.to_reference(x, y), y) # noqa: E731 + fun2 = lambda x, y: c.to_reference(c.from_reference(x, y), y) # noqa: E731 for fun, (inplace, comp) in itertools.product( (fun1, fun2), ((True, True), (False, False)) ): @@ -75,14 +75,10 @@ def test_log_converter_inplace(self): c = LogarithmicConverter(scale=1, logbase=10, logfactor=1) def from_to(value, inplace): - return c.from_reference( - c.to_reference(value, inplace), inplace - ) + return c.from_reference(c.to_reference(value, inplace), inplace) def to_from(value, inplace): - return c.to_reference( - c.from_reference(value, inplace), inplace - ) + return c.to_reference(c.from_reference(value, inplace), inplace) for fun, (inplace, comp) in itertools.product( (from_to, to_from), ((True, True), (False, False)) diff --git a/pint/util.py b/pint/util.py index b10ba6d3a..cf487705c 100644 --- a/pint/util.py +++ b/pint/util.py @@ -1,11 +1,11 @@ """ - pint.util - ~~~~~~~~~ +pint.util +~~~~~~~~~ - Miscellaneous functions for pint. +Miscellaneous functions for pint. - :copyright: 2016 by Pint Authors, see AUTHORS for more details. - :license: BSD, see LICENSE for more details. +:copyright: 2016 by Pint Authors, see AUTHORS for more details. +:license: BSD, see LICENSE for more details. """ from __future__ import annotations From e646062935dcf273b11a5e9c0dd0b2dcc458b06b Mon Sep 17 00:00:00 2001 From: Mauro Silberberg Date: Tue, 18 Feb 2025 17:42:36 -0300 Subject: [PATCH 4/5] lint: mdformat --- downstream_status.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/downstream_status.md b/downstream_status.md index 32dc4e8e4..70e5cc4a0 100644 --- a/downstream_status.md +++ b/downstream_status.md @@ -16,9 +16,9 @@ if you need a template. Then, add your project badges to this file so it can be used as a Dashboard (always putting the stable first) -| Project | stable | pre-release | nightly | +| Project | stable | pre-release | nightly | | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [Pint Downstream Demo](https://github.com/hgrecco/pint-downstream-demo) | [![CI](https://github.com/hgrecco/pint-downstream-demo/actions/workflows/ci.yml/badge.svg)](https://github.com/hgrecco/pint-downstream-demo/actions/workflows/ci.yml) | [![CI-pint-pre](https://github.com/hgrecco/pint-downstream-demo/actions/workflows/ci-pint-pre.yml/badge.svg)](https://github.com/hgrecco/pint-downstream-demo/actions/workflows/ci-pint-pre.yml) | [![CI-pint-master](https://github.com/hgrecco/pint-downstream-demo/actions/workflows/ci-pint-master.yml/badge.svg)](https://github.com/hgrecco/pint-downstream-demo/actions/workflows/ci-pint-master.yml) | -| [Pint Pandas](https://github.com/hgrecco/pint-pandas) | [![CI](https://github.com/hgrecco/pint-pandas/actions/workflows/ci.yml/badge.svg)](https://github.com/hgrecco/pint-pandas/actions/workflows/ci.yml) | [![CI-pint-pre](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-pre.yml/badge.svg)](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-pre.yml) | [![CI-pint-master](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-master.yml/badge.svg)](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-master.yml) | -| [MetPy](https://github.com/Unidata/MetPy) | [![CI](https://github.com/Unidata/MetPy/actions/workflows/tests-pypi.yml/badge.svg)](https://github.com/Unidata/MetPy/actions/workflows/tests-pypi.yml) | | [![CI-pint-master](https://github.com/Unidata/MetPy/actions/workflows/nightly-builds.yml/badge.svg)](https://github.com/Unidata/MetPy/actions/workflows/nightly-builds.yml) | -| [pint-xarray](https://github.com/xarray-contrib/pint-xarray) | [![CI](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml/badge.svg)](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml) | | [![CI-pint-master](https://github.com/xarray-contrib/pint-xarray/actions/workflows/nightly.yml/badge.svg)](https://github.com/xarray-contrib/pint-xarray/actions/workflows/nightly.yml) | +| [Pint Pandas](https://github.com/hgrecco/pint-pandas) | [![CI](https://github.com/hgrecco/pint-pandas/actions/workflows/ci.yml/badge.svg)](https://github.com/hgrecco/pint-pandas/actions/workflows/ci.yml) | [![CI-pint-pre](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-pre.yml/badge.svg)](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-pre.yml) | [![CI-pint-master](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-master.yml/badge.svg)](https://github.com/hgrecco/pint-pandas/actions/workflows/ci-pint-master.yml) | +| [MetPy](https://github.com/Unidata/MetPy) | [![CI](https://github.com/Unidata/MetPy/actions/workflows/tests-pypi.yml/badge.svg)](https://github.com/Unidata/MetPy/actions/workflows/tests-pypi.yml) | | [![CI-pint-master](https://github.com/Unidata/MetPy/actions/workflows/nightly-builds.yml/badge.svg)](https://github.com/Unidata/MetPy/actions/workflows/nightly-builds.yml) | +| [pint-xarray](https://github.com/xarray-contrib/pint-xarray) | [![CI](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml/badge.svg)](https://github.com/xarray-contrib/pint-xarray/actions/workflows/ci.yml) | | [![CI-pint-master](https://github.com/xarray-contrib/pint-xarray/actions/workflows/nightly.yml/badge.svg)](https://github.com/xarray-contrib/pint-xarray/actions/workflows/nightly.yml) | From 2737f8225fec3ff452aff03a3d49b21186e4ffb1 Mon Sep 17 00:00:00 2001 From: Mauro Silberberg Date: Tue, 18 Feb 2025 17:59:55 -0300 Subject: [PATCH 5/5] ci: fix lint task Default lint task only lints staged files. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be1afe013..e8e82e962 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: - uses: prefix-dev/setup-pixi@v0.8.2 with: environments: lint - - run: pixi run --environment lint lint + - run: pixi run --environment lint lint --all-files --show-diff-on-failure test-linux: runs-on: ubuntu-latest