qnty 0.0.5__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qnty
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: High-performance unit system library for Python with dimensional safety and fast unit conversions
5
5
  License: Apache-2.0
6
6
  Keywords: units,dimensional analysis,engineering,physics,quantities,measurements
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "qnty"
3
- version = "0.0.5"
3
+ version = "0.0.6"
4
4
  description = "High-performance unit system library for Python with dimensional safety and fast unit conversions"
5
5
  readme = "README.md"
6
6
  license = { text = "Apache-2.0" }
@@ -246,11 +246,23 @@ class BinaryOperation(Expression):
246
246
  left_str = str(self.left)
247
247
  right_str = str(self.right)
248
248
 
249
- # Add parentheses only when needed based on precedence
249
+ # Add parentheses for left side when precedence is strictly lower
250
250
  if isinstance(self.left, BinaryOperation) and precedence.get(self.left.operator, 0) < precedence.get(self.operator, 0):
251
251
  left_str = f"({left_str})"
252
- if isinstance(self.right, BinaryOperation) and precedence.get(self.right.operator, 0) < precedence.get(self.operator, 0):
253
- right_str = f"({right_str})"
252
+
253
+ # CRITICAL FIX: For right side, add parentheses when:
254
+ # 1. Precedence is strictly lower, OR
255
+ # 2. Precedence is equal AND operation is left-associative (-, /)
256
+ if isinstance(self.right, BinaryOperation):
257
+ right_prec = precedence.get(self.right.operator, 0)
258
+ curr_prec = precedence.get(self.operator, 0)
259
+
260
+ # Need parentheses if:
261
+ # - Right has lower precedence, OR
262
+ # - Same precedence and current operator is left-associative (- or /)
263
+ if (right_prec < curr_prec or
264
+ (right_prec == curr_prec and self.operator in ['-', '/'])):
265
+ right_str = f"({right_str})"
254
266
 
255
267
  return f"{left_str} {self.operator} {right_str}"
256
268
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes