qnty 0.0.5__py3-none-any.whl → 0.0.6__py3-none-any.whl

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.
qnty/expression.py CHANGED
@@ -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
 
@@ -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,7 +1,7 @@
1
1
  qnty/__init__.py,sha256=o9rtuo8QAdC3ppaD7ev1jqjrWbCvpdFbi_yZwUBuc6Q,5551
2
2
  qnty/dimension.py,sha256=uEm3p03DavihvXH7wnNkTCORZo9wPJihwEqvp4fj2lc,11110
3
3
  qnty/equation.py,sha256=XgzM91jn__GomKbgslncoFJWPDJiMb4_VKD-8sdcFXc,9096
4
- qnty/expression.py,sha256=UM0hCqOVD1gK_O5-Rsq7BWIPDTEL_kFORprV6LIqGcU,20890
4
+ qnty/expression.py,sha256=WV0OfZYPZlNf_sBEgOrnG88KKzj-xvTn45YGMoZR1xc,21435
5
5
  qnty/prefixes.py,sha256=bRwcNbE_nX9gXI_WnJZLL-i7kQncIOZivCCSN8dur2g,6000
6
6
  qnty/unit.py,sha256=dTKaQ9gsO1rom0JJJ3MYjVaSCuCEU9018DWClTBv7w4,5569
7
7
  qnty/unit_types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -14,6 +14,6 @@ qnty/variable_types/expression_variable.py,sha256=sRQ4VUMLBEh6tPqOwh4gLtGQH9Y3Xe
14
14
  qnty/variable_types/typed_variable.py,sha256=kjw8VOShMaE7iorc3mqCIApYaFgOfvv-jSu_tmT1DgM,4227
15
15
  qnty/variables.py,sha256=amlj4xGMC_nuo9sQtGRMG5SAcX4WKK-YWNyXs1yzNbQ,142668
16
16
  qnty/variables.pyi,sha256=KYPDJ-Qh_LPP4vHsafzrV6ZAUeepErY-RwRpOTieuhk,219690
17
- qnty-0.0.5.dist-info/METADATA,sha256=20alPqNoEvN-svnuc9s9nZCXuFlvx-1HpYDOmnjhVsM,12113
18
- qnty-0.0.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
- qnty-0.0.5.dist-info/RECORD,,
17
+ qnty-0.0.6.dist-info/METADATA,sha256=l_noQC2KY0pSXEypKP-WPVe_uPVwMRwa-ECnubcRS-E,12113
18
+ qnty-0.0.6.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
+ qnty-0.0.6.dist-info/RECORD,,
File without changes