Skip to content

Commit 719f5ae

Browse files
iloveitalyanntzer
authored andcommitted
fix: support for new ipython 9.x theme system
1 parent fb83a21 commit 719f5ae

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ by adding ``c.Completer.use_jedi = False`` to the ``ipython_config.py`` file.
101101
Changelog
102102
---------
103103

104+
next
105+
~~~~
106+
- Fix compatibility with IPython 9's new theme system.
107+
104108
v0.5
105109
~~~~
106110
- Avoid erroring when exiting IPython≥8.15.

src/ipython_autoimport.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,16 @@ def _report(ipython, msg):
8989
sys.stdout._raw = True
9090
except AttributeError:
9191
pass
92-
cs = PyColorize.Parser().color_table[ipython.colors].colors
93-
# Token.NUMBER: bright blue (cyan), looks reasonable.
94-
print("{}Autoimport:{} {}".format(cs[token.NUMBER], cs["normal"], msg))
92+
if IPython.version_info >= (9,):
93+
import pygments # Only a dependency from IPython 4.2.0.
94+
print(PyColorize.theme_table[ipython.colors].format([
95+
(pygments.token.Number, "Autoimport: "),
96+
(pygments.token.Text, msg),
97+
]))
98+
else:
99+
cs = PyColorize.Parser().color_table[ipython.colors].colors
100+
# Token.NUMBER: bright blue (cyan), looks reasonable.
101+
print("{}Autoimport:{} {}".format(cs[token.NUMBER], cs["normal"], msg))
95102

96103

97104
class _SubmoduleAutoImporterModule(ModuleType):

0 commit comments

Comments
 (0)