summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorKeewis <keewis@posteo.de>2021-08-17 15:22:24 +0200
committerKeewis <keewis@posteo.de>2021-08-17 15:22:24 +0200
commit47c0b067422e2e2919dc27be38d4012b9c667f39 (patch)
tree49916eeb7a87bb64812ca9cd180cc5376596385f /pint
parentdd396436f2dc7ff2267705e59e5c6a5756f802b2 (diff)
downloadpint-47c0b067422e2e2919dc27be38d4012b9c667f39.tar.gz
add back `_FORMATS` so `Measurement.__format__` does not break
Diffstat (limited to 'pint')
-rw-r--r--pint/formatting.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/pint/formatting.py b/pint/formatting.py
index 94308d1..7ea042b 100644
--- a/pint/formatting.py
+++ b/pint/formatting.py
@@ -70,6 +70,53 @@ def _pretty_fmt_exponent(num):
return ret
+#: _FORMATS maps format specifications to the corresponding argument set to
+#: formatter().
+_FORMATS: Dict[str, dict] = {
+ "P": { # Pretty format.
+ "as_ratio": True,
+ "single_denominator": False,
+ "product_fmt": "ยท",
+ "division_fmt": "/",
+ "power_fmt": "{}{}",
+ "parentheses_fmt": "({})",
+ "exp_call": _pretty_fmt_exponent,
+ },
+ "L": { # Latex format.
+ "as_ratio": True,
+ "single_denominator": True,
+ "product_fmt": r" \cdot ",
+ "division_fmt": r"\frac[{}][{}]",
+ "power_fmt": "{}^[{}]",
+ "parentheses_fmt": r"\left({}\right)",
+ },
+ "Lx": {"siopts": "", "pm_fmt": " +- "}, # Latex format with SIunitx.
+ "H": { # HTML format.
+ "as_ratio": True,
+ "single_denominator": True,
+ "product_fmt": r" ",
+ "division_fmt": r"{}/{}",
+ "power_fmt": r"{}<sup>{}</sup>",
+ "parentheses_fmt": r"({})",
+ },
+ "": { # Default format.
+ "as_ratio": True,
+ "single_denominator": False,
+ "product_fmt": " * ",
+ "division_fmt": " / ",
+ "power_fmt": "{} ** {}",
+ "parentheses_fmt": r"({})",
+ },
+ "C": { # Compact format.
+ "as_ratio": True,
+ "single_denominator": False,
+ "product_fmt": "*", # TODO: Should this just be ''?
+ "division_fmt": "/",
+ "power_fmt": "{}**{}",
+ "parentheses_fmt": r"({})",
+ },
+}
+
#: _FORMATTERS maps format names to callables doing the formatting
_FORMATTERS: Dict[str, Callable] = {}