tags 1022469 +patch thanks Hi,
On Wed, Nov 23, 2022 at 07:48:47PM +1100, Stuart Prescott wrote: > pint is incompatible with babel > 2.8; unfortunately, Debian now has babel > 2.10. > > So far, upstream has only noted the compatibility with version pinning. > > https://github.com/hgrecco/pint/issues/1219 > > Upstream tests for newer releases of pint also now fail due to this same > reason. Looks like they got a work-around here in (since closed) PR #1401: https://github.com/hgrecco/pint/commit/eb4e13428a3ede09148b76c71bc5b8cddb169176.patch If I stick this (also attached) patch in, the testsuite passes fine. > (and we should enable autopkgtest tests for pint and then this would have > been caught as soon as babel > 2.8 was uploaded) Yeah. Michael
>From eb4e13428a3ede09148b76c71bc5b8cddb169176 Mon Sep 17 00:00:00 2001 From: Hernan <hernan.gre...@gmail.com> Date: Wed, 27 Oct 2021 20:36:40 -0300 Subject: [PATCH] Support for babel > 2.8 Close #1400, #1219 and #1296. --- pint/formatting.py | 11 ++++++++--- pint/testsuite/test_issues.py | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pint/formatting.py b/pint/formatting.py index a04205dd9..528f4e03e 100644 --- a/pint/formatting.py +++ b/pint/formatting.py @@ -333,9 +333,14 @@ def formatter( # Don't remove this positional! This is the format used in Babel key = pat.replace("{0}", "").strip() break - division_fmt = compound_unit_patterns.get("per", {}).get( - babel_length, division_fmt - ) + + tmp = compound_unit_patterns.get("per", {}).get(babel_length, division_fmt) + + try: + division_fmt = tmp.get("compound", division_fmt) + except AttributeError: + division_fmt = tmp + power_fmt = "{}{}" exp_call = _pretty_fmt_exponent if value == 1: diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index ed781b72f..9d4167c02 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -824,6 +824,14 @@ def test_issue_1300(self): m = ureg.Measurement(1, 0.1, "meter") assert m.default_format == "~P" + def test_issue_1400(self, sess_registry): + q1 = 3 * sess_registry.W + q2 = 3 * sess_registry.W / sess_registry.cm + assert q1.format_babel("~", locale="es_Ar") == "3 W" + assert q1.format_babel("", locale="es_Ar") == "3 vatios" + assert q2.format_babel("~", locale="es_Ar") == "3.0 W / cm" + assert q2.format_babel("", locale="es_Ar") == "3.0 vatios por centÃmetros" + if np is not None: