Skip to content
Prev Previous commit
Next Next commit
autobalance: make AutoBalancer usable without shell with default beha…
…vior
  • Loading branch information
jb-leger committed Jun 12, 2023
commit b3c3de54fe2f5e1df82b1a30598b284a53921192
11 changes: 8 additions & 3 deletions IPython/core/inputtransformer2.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ class AutoBalancer:

has_side_effects: bool = True

def __init__(self, shell):
def __init__(self, shell=None, default=False):
self._shell = shell
self._default = default

def __call__(self, lines):
"""For single line cell, add necessary [{( and )}] to balance."""
Expand All @@ -251,12 +252,16 @@ def __call__(self, lines):
# apply only for single line cell
return lines

if self._shell is None or not self._shell.autobalance:
if self._shell is None:
if not self._default:
return lines
elif not self._shell.autobalance:
return lines

modified, new_line = _autobalance_line(lines[0])
if modified:
self._shell.auto_rewrite_input(new_line)
if self._shell is not None:
self._shell.auto_rewrite_input(new_line)
return [new_line]
return lines

Expand Down