Replace specified operand/operator.
(self, old, new)
| 115 | return any(arg.has(*vars) for arg in self.args if isinstance(arg, Operand)) |
| 116 | |
| 117 | def replace(self, old, new): |
| 118 | """Replace specified operand/operator.""" |
| 119 | # Check for entire expression match |
| 120 | if self == old: |
| 121 | return new |
| 122 | # Check base and call with replaced arguments |
| 123 | elif isinstance(old, type) and isinstance(self,old): |
| 124 | args = [arg.replace(old, new) if isinstance(arg, Operand) else arg for arg in self.args] |
| 125 | return new(*args) |
| 126 | # Call with replaced arguments |
| 127 | else: |
| 128 | args = [arg.replace(old, new) if isinstance(arg, Operand) else arg for arg in self.args] |
| 129 | return self.new_operands(*args) |
| 130 | |
| 131 | # def simplify(self, *vars): |
| 132 | # """Simplify expression, except subtrees containing specified variables.""" |
no test coverage detected