summaryrefslogtreecommitdiff
path: root/pint/util.py
diff options
context:
space:
mode:
authorJules Chéron <jules.cheron@gmail.com>2021-08-02 18:32:53 +0200
committerJules Chéron <jules.cheron@gmail.com>2021-08-05 00:15:29 +0200
commit1de1b5cddc92c97bb3f8dc79ca837e2fbbe6efe3 (patch)
tree4337d3a6ce8ffee1293731879ef6d6efc8e542d7 /pint/util.py
parent1d566538f8ee47fbf7c9127e0385fec8de0d9b78 (diff)
downloadpint-1de1b5cddc92c97bb3f8dc79ca837e2fbbe6efe3.tar.gz
Fix #1360 parsing units with same exponents but different sign
Diffstat (limited to 'pint/util.py')
-rw-r--r--pint/util.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/pint/util.py b/pint/util.py
index 18474ec..b0fed09 100644
--- a/pint/util.py
+++ b/pint/util.py
@@ -771,7 +771,7 @@ _subs_re = [
(re.compile(a.format(r"[_a-zA-Z][_a-zA-Z0-9]*")), b) for a, b in _subs_re_list
]
_pretty_table = str.maketrans("⁰¹²³⁴⁵⁶⁷⁸⁹·⁻", "0123456789*-")
-_pretty_exp_re = re.compile(r"⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+(?:\.[⁰¹²³⁴⁵⁶⁷⁸⁹]*)?")
+_pretty_exp_re = re.compile(r"(⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+(?:\.[⁰¹²³⁴⁵⁶⁷⁸⁹]*)?)")
def string_preprocessor(input_string: str) -> str:
@@ -781,10 +781,8 @@ def string_preprocessor(input_string: str) -> str:
for a, b in _subs_re:
input_string = a.sub(b, input_string)
+ input_string = _pretty_exp_re.sub(r"**(\1)", input_string)
# Replace pretty format characters
- for pretty_exp in _pretty_exp_re.findall(input_string):
- exp = "**" + pretty_exp.translate(_pretty_table)
- input_string = input_string.replace(pretty_exp, exp)
input_string = input_string.translate(_pretty_table)
# Handle caret exponentiation