From ecd8232c003e4d9d144daa5afd4bb0ea75fb589d Mon Sep 17 00:00:00 2001 From: Justin DuJardin Date: Mon, 5 Feb 2024 15:20:11 -0800 Subject: [PATCH] chore: fix lint from inadequate typing --- mathy_core/rules/multiplicative_inverse.py | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mathy_core/rules/multiplicative_inverse.py b/mathy_core/rules/multiplicative_inverse.py index 8942d1f..d54f309 100644 --- a/mathy_core/rules/multiplicative_inverse.py +++ b/mathy_core/rules/multiplicative_inverse.py @@ -52,25 +52,25 @@ def apply_to(self, node: MathExpression) -> ExpressionChangeRule: assert tree_type is not None, "call can_apply_to before applying a rule" change.save_parent() # connect result to node.parent - # Handle the division based on the tree type - if tree_type == _OP_DIVISION_EXPRESSION: - result = MultiplyExpression( - node.left.clone(), - DivideExpression(ConstantExpression(1), node.right.clone()), - ) + assert node.left is not None, "Division must have a left child" + assert node.right is not None, "Division must have a right child" - elif tree_type == _OP_DIVISION_NEGATIVE_DENOMINATOR: + if tree_type == _OP_DIVISION_NEGATIVE_DENOMINATOR: # For division by a negative denominator, negate the numerator and use the positive reciprocal + assert isinstance( + node.right, NegateExpression + ), "Right child must be a NegateExpression" + child = node.right.get_child() + assert child is not None, "NegateExpression must have a child" result = MultiplyExpression( node.left.clone(), - DivideExpression( - ConstantExpression(-1), node.right.get_child().clone() - ), + DivideExpression(ConstantExpression(-1), child.clone()), ) - + # Handle the division based on the tree type else: - raise NotImplementedError( - "Unsupported tree configuration for MultiplicativeInverseRule" + result = MultiplyExpression( + node.left.clone(), + DivideExpression(ConstantExpression(1), node.right.clone()), ) result.set_changed() # mark this node as changed for visualization