Add parentheses around a string if it contains an operator and is not already parenthesized. An exception is made for '*' which is common and harmless in the context where the symbolic size is used.
(sym: str)
| 10 | PRINT_STACKS = False |
| 11 | |
| 12 | def maybe_parenthesize(sym: str) -> str: |
| 13 | """Add parentheses around a string if it contains an operator |
| 14 | and is not already parenthesized. |
| 15 | |
| 16 | An exception is made for '*' which is common and harmless |
| 17 | in the context where the symbolic size is used. |
| 18 | """ |
| 19 | if sym.startswith("(") and sym.endswith(")"): |
| 20 | return sym |
| 21 | if re.match(r"^[\s\w*]+$", sym): |
| 22 | return sym |
| 23 | else: |
| 24 | return f"({sym})" |
| 25 | |
| 26 | |
| 27 | def var_size(var: StackItem) -> str: |
no test coverage detected
searching dependent graphs…