ipython / ipython

Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
https://ipython.readthedocs.org
BSD 3-Clause "New" or "Revised" License
16.25k stars 4.43k forks source link

History reversed with older prompt_toolkit #13634

Open MegaBluejay opened 2 years ago

MegaBluejay commented 2 years ago

When using an older version of prompt-toolkit (3.0.7), history does not work correctly. Upon opening ipython, both when scrolling with the arrow keys and searching, a second copy of it appears, in reversed order. This does not affect the actual history file, only how it looks in this environment.

Example: real history

a = 1
b = 2
c = 3

apparent history

a = 1
b = 2
c = 3
c = 3
b = 2
a = 1

Then upon entering another command the first half vanishes, leaving only the reversed, with no new entries being added

> d = 4

apparent history

c = 3
b = 2
a = 1

The new history is added to the file as usual, but not displayed.

Environment:

> python -c "import IPython; print(IPython.sys_info())"
{'commit_hash': 'e643224',
 'commit_source': 'repository',
 'default_encoding': 'utf-8',
 'ipython_path': '/home/archer/test/ipython/IPython',
 'ipython_version': '8.3.0.dev',
 'os_name': 'posix',
 'platform': 'Linux-5.15.32-1-MANJARO-x86_64-with-glibc2.35',
 'sys_executable': '/home/archer/.virtualenvs/test/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]'}

prompt-toolkit version: 3.0.7 The issue is not present with the latest prompt-toolkit: version 3.0.29, or with versions of ipython before 8.2.0 If bumping the dependency version is viable, it seems like the easiest fix.

segasai commented 2 years ago

I think this is related to #13631 (or it is the same issue). I don't think the prompt-toolkit versions mattered there though.

uamoti commented 2 years ago

I've had a similar issue where the command history would appear in reverse order, from oldest to newest. Likewise, it started with the latest update to IPython 8.2.0, and upgrading prompt_toolkit seems to have solved the issue.

mcmahanp commented 2 years ago

I've had a similar issue where the command history would appear in reverse order, from oldest to newest. Likewise, it started with the latest update to IPython 8.2.0, and upgrading prompt_toolkit seems to have solved the issue.

I was about to submit a new issue exactly on this (with ipython 8.3.0) when I saw your comment. Updating prompt_toolkit did the trick. Thank you!

sbuchbinder commented 2 years ago

Agreed with above: history was messed up with python 8.3.0 and prompt_toolkit 3.0.8

Updating to prompt_toolkit 3.0.29 (latest) resolved the issue.

Tim-K-DFW commented 2 years ago

Same here with 8.4.0. Upgrading prompt-toolkit to 3.0.29 has not changed anything. Downgrading ipython to 8.0.0 has fixed it.

sleepyhollo commented 2 years ago

Also have a similar issue. Using python 3.8.6, ipython 8.4.0 in windows 10. I have prompt_toolkit version '3.0.29'.

I see two problems

Downgrading to v8.0.0 also resolves it for me

ekieflabc commented 2 years ago

Same problem and no solution :\

▶ python -c "import IPython; print(IPython.sys_info())"
{'commit_hash': '4396dd620',
 'commit_source': 'installation',
 'default_encoding': 'utf-8',
 'ipython_path': '(...)/.conda/lib/python3.8/site-packages/IPython',
 'ipython_version': '8.4.0',
 'os_name': 'posix',
 'platform': 'macOS-10.16-x86_64-i386-64bit',
 'sys_executable': '(...)/.conda/bin/python',
 'sys_platform': 'darwin',
 'sys_version': '3.8.13 | packaged by conda-forge | (default, Mar 25 2022, '
                '06:06:49) \n'
                '[Clang 12.0.1 ]'}
umutdz commented 2 years ago

I've had a similar issue and it was fixed after I updated prompt-toolkit: version 3.0.30 and version of ipython 8.4.0