Skip to content

Commit

Permalink
Fix up pre-commit formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Tiemann <[email protected]>
  • Loading branch information
MichaelTiemannOSC committed Jan 23, 2024
1 parent b1b941b commit f6fbcc0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Pint Changelog
0.24 (unreleased)
-----------------

- Nothing changed yet.
- Add `dim_sort` function to _formatter_helpers.
- Add `dim_order` and `default_sort_func` properties to FullFormatter.
(PR #????, fixes Issue #1841)


0.23 (2023-12-08)
Expand Down
2 changes: 1 addition & 1 deletion pint/delegates/formatter/_format_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def dim_sort(items: Iterable[tuple[str, Number]], registry: UnitRegistry):
KeyError
If unit cannot be found in the registry.
"""

if registry is None:
return items
ret_dict = dict()
Expand Down
6 changes: 4 additions & 2 deletions pint/delegates/formatter/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Callable, Literal, Optional, Any
from typing import TYPE_CHECKING, Callable, Iterable, Literal, Optional, Any
import locale
from ...compat import babel_parse, Number, Unpack
from ...util import iterable
Expand Down Expand Up @@ -49,7 +49,9 @@ class FullFormatter:
"[time]",
"[temperature]",
)
default_sort_func: Optional[Callable[Iterable[tuple[str, Number]]], Iterable[tuple[str, Number]]] = None
default_sort_func: Optional[
Callable[Iterable[tuple[str, Number]]], Iterable[tuple[str, Number]]
] = None

locale: Optional[Locale] = None
babel_length: Literal["short", "long", "narrow"] = "long"
Expand Down
4 changes: 3 additions & 1 deletion pint/delegates/formatter/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def format_unit(
division_fmt=r"{}/{}",
power_fmt=r"{}<sup>{}</sup>",
parentheses_fmt=r"({})",
sort_func=lambda x: unit._REGISTRY.formatter.default_sort_func(x, unit._REGISTRY),
sort_func=lambda x: unit._REGISTRY.formatter.default_sort_func(
x, unit._REGISTRY
),
)

def format_quantity(
Expand Down
4 changes: 3 additions & 1 deletion pint/delegates/formatter/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ def format_unit(
power_fmt="{}{}",
parentheses_fmt="({})",
exp_call=pretty_fmt_exponent,
sort_func=lambda x: unit._REGISTRY.formatter.default_sort_func(x, unit._REGISTRY),
sort_func=lambda x: unit._REGISTRY.formatter.default_sort_func(
x, unit._REGISTRY
),
)

def format_quantity(
Expand Down
9 changes: 3 additions & 6 deletions pint/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,16 +1158,15 @@ def test_issues_1505():


def test_issues_1841(subtests):
import pint
from pint.delegates.formatter._format_helpers import dim_sort

ur = UnitRegistry()
ur.formatter.default_sort_func = dim_sort

for x, spec, result in (
(ur.Unit(UnitsContainer(hour=1,watt=1)), "P~", "W·h"),
(ur.Unit(UnitsContainer(ampere=1,volt=1)), "P~", "V·A"),
(ur.Unit(UnitsContainer(meter=1,newton=1)), "P~", "N·m"),
(ur.Unit(UnitsContainer(hour=1, watt=1)), "P~", "W·h"),
(ur.Unit(UnitsContainer(ampere=1, volt=1)), "P~", "V·A"),
(ur.Unit(UnitsContainer(meter=1, newton=1)), "P~", "N·m"),
):
with subtests.test(spec):
ur.default_format = spec
Expand All @@ -1177,9 +1176,7 @@ def test_issues_1841(subtests):

@pytest.mark.xfail
def test_issues_1841_xfail():
import pint
from pint import formatting as fmt
import pint.delegates.formatter._format_helpers
from pint.delegates.formatter._format_helpers import dim_sort

# sets compact display mode by default
Expand Down

0 comments on commit f6fbcc0

Please sign in to comment.