Skip to content

Commit 06520ea

Browse files
committed
Fix bug when using ipy with gnureadline and Python 3.13
1 parent 285d959 commit 06520ea

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cmd2/cmd2.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@
128128
StatementParser,
129129
shlex_split,
130130
)
131+
132+
# NOTE: When using gnureadline with Python 3.13, start_ipython needs to be imported before any readline-related stuff
133+
try:
134+
from IPython import start_ipython
135+
except ImportError:
136+
pass
137+
131138
from .rl_utils import (
132139
RlType,
133140
rl_escape_prompt,
@@ -4629,9 +4636,13 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover
46294636
# Detect whether IPython is installed
46304637
try:
46314638
import traitlets.config.loader as TraitletsLoader # type: ignore[import]
4632-
from IPython import ( # type: ignore[import]
4633-
start_ipython,
4634-
)
4639+
4640+
# Allow users to install ipython from a cmd2 prompt when needed and still have ipy command work
4641+
try:
4642+
start_ipython # noqa F823
4643+
except NameError:
4644+
from IPython import start_ipython
4645+
46354646
from IPython.terminal.interactiveshell import ( # type: ignore[import]
46364647
TerminalInteractiveShell,
46374648
)

0 commit comments

Comments
 (0)