summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorBenjamin W. Portner <benjamin.portner@bauhaus-luftfahrt.net>2023-01-19 19:28:05 +0100
committerBenjamin W. Portner <benjamin.portner@bauhaus-luftfahrt.net>2023-01-19 19:28:05 +0100
commiteecd0d97998bc34200b8d073ecbbad9361c04ecf (patch)
treea54e15eabb1230f85bad2d015417823752ac8628 /pint
parent05066e0e791f84ca03ed34643348b5348e2f5786 (diff)
downloadpint-eecd0d97998bc34200b8d073ecbbad9361c04ecf.tar.gz
modify string pre-processing such that multiplication operator is inserted before and after brackets, e.g. 2 (3 + 4) -> 2 * (3 + 4)
Diffstat (limited to 'pint')
-rw-r--r--pint/testsuite/test_pint_eval.py10
-rw-r--r--pint/util.py2
2 files changed, 6 insertions, 6 deletions
diff --git a/pint/testsuite/test_pint_eval.py b/pint/testsuite/test_pint_eval.py
index d396929..b5b94f0 100644
--- a/pint/testsuite/test_pint_eval.py
+++ b/pint/testsuite/test_pint_eval.py
@@ -106,9 +106,9 @@ class TestPintEval:
# implicit op
("3 4", "(3 * 4)"),
# implicit op, then parentheses
- ("3 (2 + 4)", "(3 (2 + 4))"),
+ ("3 (2 + 4)", "(3 * (2 + 4))"),
# parentheses, then implicit
- ("(3 ** 4 ) 5", "((3 ** 4) 5)"),
+ ("(3 ** 4 ) 5", "((3 ** 4) * 5)"),
# implicit op, then exponentiation
("3 4 ** 5", "(3 * (4 ** 5))"),
# implicit op, then addition
@@ -116,7 +116,7 @@ class TestPintEval:
# power followed by implicit
("3 ** 4 5", "((3 ** 4) * 5)"),
# implicit with parentheses
- ("3 (4 ** 5)", "(3 (4 ** 5))"),
+ ("3 (4 ** 5)", "(3 * (4 ** 5))"),
# exponent with e
("3e-1", "3e-1"),
# multiple units with exponents
@@ -136,8 +136,8 @@ class TestPintEval:
# units should behave like numbers, so we don't need a bunch of extra tests for them
# implicit op, then addition
("3 kg + 5", "((3 * kg) + 5)"),
- ("(5 % 2) m", "((5 % 2) m)"), # mod operator
- ("(5 // 2) m", "((5 // 2) m)"), # floordiv operator
+ ("(5 % 2) m", "((5 % 2) * m)"), # mod operator
+ ("(5 // 2) m", "((5 // 2) * m)"), # floordiv operator
),
)
def test_preprocessed_eval_tree(self, input_text, parsed):
diff --git a/pint/util.py b/pint/util.py
index 852dd41..97db5d9 100644
--- a/pint/util.py
+++ b/pint/util.py
@@ -765,7 +765,7 @@ _subs_re_list = [
r"\b([0-9]+\.?[0-9]*)(?=[e|E][a-zA-Z]|[a-df-zA-DF-Z])",
r"\1*",
), # Handle numberLetter for multiplication
- (r"([\w\.])\s+(?=\w)", r"\1*"), # Handle space for multiplication
+ (r"([\w\.\)])\s+(?=[\w\(])", r"\1*"), # Handle space for multiplication
]
#: Compiles the regex and replace {} by a regex that matches an identifier.