Skip to content

[Bug]: matplotlib figures inhibit input longer than 100 chars in IPython #25756

@jdtsmith

Description

@jdtsmith

Bug summary

After matplotlib activates a plot in IPython, input behavior is changed. In particular, input longer than 100 characters is no longer directly accepted. Since IPython uses input in its REPL loop when --simple-prompt is set, this defeats various modes (such as Emacs) which use this.

Code for reproduction

% python3 -m IPython --simple-prompt
Python 3.11.3 (main, Apr  7 2023, 19:29:16) [Clang 14.0.0 (clang-1400.0.29.202)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: input('Test1: '); print("success!")
Test1: avaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravar=3
success!

In [2]: import matplotlib.pyplot as plt; plt.plot([1])
Installed osx event loop hook.
Out[2]: [<matplotlib.lines.Line2D at 0x10a704a10>]

In [3]: input('Test2: '); print("success!")
Test2: avaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravaravar=3
# Return does not send the input

Actual outcome

To send the input, an additional newline is required, which is then interpreted as an additional (blank) command. Commands shorter than 100 characters are still directly accepted.

Expected outcome

Python's native input should work the same in IPython before and after activating a matplotlib figure, for arbitrary command lengths (up to the terminals line length limit).

Additional information

Issue posted with IPython as well: ipython/ipython#14030. I have tested disabling enable_gui, but this is not the culprit. To see the bug, you must actually create a figure (but do not need to show it). This does not occur in regular python sessions, only IPython (and possibly only on MacOS?).

Operating system

MacOS 12.6

Matplotlib Version

3.7.1 (same behavior on various versions back to 3.4)

Matplotlib Backend

MacOSX (though same behavior with other backends, e.g. qt6)

Python version

3.11.3 (same behavior back to 3.9)

Jupyter version

n/a

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions