René's URL Explorer Experiment


Title: `readline.set_history_length` corrupts history files when used in a libedit build · Issue #121160 · python/cpython · GitHub

Open Graph Title: `readline.set_history_length` corrupts history files when used in a libedit build · Issue #121160 · python/cpython

X Title: `readline.set_history_length` corrupts history files when used in a libedit build · Issue #121160 · python/cpython

Description: Bug report Bug description: Since the libedit transition (correction: If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions related to history files are broken. It is inc...

Open Graph Description: Bug report Bug description: Since the libedit transition (correction: If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions relate...

X Description: Bug report Bug description: Since the libedit transition (correction: If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions relate...

Opengraph URL: https://github.com/python/cpython/issues/121160

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`readline.set_history_length` corrupts history files when used in a libedit build","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n~~Since the libedit transition~~ ([correction](https://github.com/python/cpython/issues/121160#issuecomment-2200501386): If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions related to history files are broken. \r\n\r\n1. It is inconvenient enough that history files written by GNU readline based `readline` module are unreadable and result in a rather confusing `OSError` with `exc.errno == errno.EINVAL` (without a corresponding operating system routine that returns such an error), but a workaround intercepting this `OSError` can be written that converts the old format to the new one. This has been covered before, e.g. in https://github.com/python/cpython/issues/120766.\r\n2. More importantly, history files written by libedit based `readline` module are unreadable by itself when `set_history_length` is used, as demonstrated by the code below.\r\n3. While a workaround for that is also possible (also below), as far as I can tell, until 3.13, so until a year from now (?) (whenever https://github.com/python/cpython/issues/112510 becomes available in a release), your only option is `\"libedit\" in readline.__doc__`, which I expect will be what many people will leave in the codebase even once `readline.backend` becomes available.\r\n\r\nReproducer:\r\n\r\n```python\r\nimport readline\r\n\r\nreadline.add_history(\"foo bar\")\r\nreadline.add_history(\"nope nope\")\r\nreadline.write_history_file(\"history-works\")\r\n\r\n# this works:\r\nreadline.read_history_file(\"history-works\")\r\n\r\nreadline.set_history_length(2)\r\nreadline.write_history_file(\"history-breaks\")\r\n\r\n# this breaks:\r\nreadline.read_history_file(\"history-breaks\")\r\n```\r\n\r\nWorkaround:\r\n\r\n```python\r\ndef _is_using_libedit():\r\n    if hasattr(readline, \"backend\"):\r\n        return readline.backend == \"editline\"\r\n    else:\r\n        return \"libedit\" in readline.__doc__\r\n\r\nreadline.set_history_length(1000)\r\nif _is_using_libedit():\r\n    readline.replace_history_item(\r\n        max(0, readline.get_current_history_length() - readline.get_history_length()),\r\n        \"_HiStOrY_V2_\")\r\n```\r\n\r\n### CPython versions tested on:\r\n\r\n3.12\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-121326\n* gh-121327\n* gh-121856\n* gh-121857\n* gh-122030\n* gh-122031\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/whitequark","@type":"Person","name":"whitequark"},"datePublished":"2024-06-29T15:58:02Z","url":"https://github.com/python/cpython/issues/121160"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:49f528b5-4622-f836-003a-e94e5374dc2b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id840C:4BB79:38298B0:47BEE24:6B01FE94
html-safe-nonce196fd65844f5b20bf445c6a3d5aff4d9bf9206df7a06c8f75262d2f466cea327
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDBDOjRCQjc5OjM4Mjk4QjA6NDdCRUUyNDo2QjAxRkU5NCIsInZpc2l0b3JfaWQiOiI4MzYzOTkzODE4MDc3NTg5OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac3ce241522ec618f5ec3dc14207a810a077d1e4d882905a192daa06f7fa9569bc
hovercard-subject-tagissue:2381826981
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/121160/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7dccefa0a960625870af3846670a1020532e049506553e781a6216ceeae7d2fc/python/cpython/issues/121160
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7dccefa0a960625870af3846670a1020532e049506553e781a6216ceeae7d2fc/python/cpython/issues/121160
og:image:altBug report Bug description: Since the libedit transition (correction: If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions relate...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamewhitequark
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/121160#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F121160
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F121160
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/121160
Reloadhttps://github.com/python/cpython/issues/121160
Reloadhttps://github.com/python/cpython/issues/121160
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/121160
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/121160
readline.set_history_length corrupts history files when used in a libedit buildhttps://github.com/python/cpython/issues/121160#top
topic-replRelated to the interactive shellhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-repl%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jun 29, 2024https://github.com/python/cpython/issues/121160#issue-2381826981
correctionhttps://github.com/python/cpython/issues/121160#issuecomment-2200501386
The New REPL Does Not Load My Command History #120766https://github.com/python/cpython/issues/120766
Add readline.backend for the backend readline uses #112510https://github.com/python/cpython/issues/112510
gh-121160: Add a test for readline.set_history_length #121326https://github.com/python/cpython/pull/121326
gh-121160: Note that readline libraries using different history formats. #121327https://github.com/python/cpython/pull/121327
[3.13] gh-121160: Add some tests for readline.set_history_length (GH-121326) #121856https://github.com/python/cpython/pull/121856
[3.12] gh-121160: Add some tests for readline.set_history_length (GH-121326) #121857https://github.com/python/cpython/pull/121857
[3.13] gh-121160: Note that readline libraries using different history formats. (GH-121327) #122030https://github.com/python/cpython/pull/122030
[3.12] gh-121160: Note that readline libraries using different history formats. (GH-121327) #122031https://github.com/python/cpython/pull/122031
Nexthttps://github.com/python/cpython/issues/121160?timeline_page=1
whitequarkhttps://github.com/whitequark
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Jun 29, 2024https://github.com/python/cpython/issues/121160#event-13339854832
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jun 29, 2024https://github.com/python/cpython/issues/121160#issuecomment-2198246116
whitequarkhttps://github.com/whitequark
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jun 29, 2024https://github.com/python/cpython/issues/121160#event-13339874201
whitequarkhttps://github.com/whitequark
on Jun 29, 2024https://github.com/python/cpython/issues/121160#event-13339874297
sobolevnhttps://github.com/sobolevn
topic-replRelated to the interactive shellhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-repl%22
on Jun 30, 2024https://github.com/python/cpython/issues/121160#event-13342138419
https://github.com/encukou
encukouhttps://github.com/encukou
on Jul 1, 2024https://github.com/python/cpython/issues/121160#issuecomment-2199633461
@whitequarkhttps://github.com/whitequark
history_truncate_filehttps://www.man7.org/linux/man-pages/man3/history.3.html
https://github.com/encukou
encukouhttps://github.com/encukou
on Jul 1, 2024https://github.com/python/cpython/issues/121160#issuecomment-2199639506
in the other issuehttps://github.com/python/cpython/issues/112510#issuecomment-2198247498
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jul 1, 2024https://github.com/python/cpython/issues/121160#issuecomment-2200501386
python-build-standalonehttps://github.com/indygreg/python-build-standalone
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jul 1, 2024https://github.com/python/cpython/issues/121160#issuecomment-2200516950
history_truncate_filehttps://www.man7.org/linux/man-pages/man3/history.3.html
I know the painhttps://github.com/GlasgowEmbedded/glasgow/blob/00ad180b0a0a5d1e56f1d1be4a53fcbea4ff590b/software/glasgow/support/plugin.py#L18-L44
encukouhttps://github.com/encukou
on Jul 3, 2024https://github.com/python/cpython/issues/121160#event-13379207955
pythongh-121160: Add a test for readline.set_history_lengthhttps://github.com/encukou/cpython/commit/ba60eae46b4f925a72925da638ea0b2b9f3edd85
pythongh-121160https://github.com/python/cpython/issues/121160
ba60eaehttps://github.com/encukou/cpython/commit/ba60eae46b4f925a72925da638ea0b2b9f3edd85
pythongh-121160: Note that readline libraries using different history…https://github.com/encukou/cpython/commit/258d375369ddced620612fa96a0c75a83a587776
pythongh-121160https://github.com/python/cpython/issues/121160
258d375https://github.com/encukou/cpython/commit/258d375369ddced620612fa96a0c75a83a587776
https://github.com/encukou
encukouhttps://github.com/encukou
on Jul 3, 2024https://github.com/python/cpython/issues/121160#issuecomment-2205938550
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jul 3, 2024https://github.com/python/cpython/issues/121160#issuecomment-2206361598
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jul 3, 2024https://github.com/python/cpython/issues/121160#issuecomment-2206362590
encukouhttps://github.com/encukou
on Jul 16, 2024https://github.com/python/cpython/issues/121160#event-13521707998
gh-121160: Add some tests for readline.set_history_length (GH-121326)https://github.com/python/cpython/commit/263c7e611bb24715e513d457a3477a61fff15162
gh-121160https://github.com/python/cpython/issues/121160
GH-121326https://github.com/python/cpython/pull/121326
263c7e6https://github.com/python/cpython/commit/263c7e611bb24715e513d457a3477a61fff15162
encukouhttps://github.com/encukou
on Jul 19, 2024https://github.com/python/cpython/issues/121160#event-13575219938
[3.12] pythongh-121160: Note that readline libraries using different …https://github.com/encukou/cpython/commit/21ea75a6ebe50c9de70715951af10edd2e5779b0
pythongh-121160https://github.com/python/cpython/issues/121160
21ea75ahttps://github.com/encukou/cpython/commit/21ea75a6ebe50c9de70715951af10edd2e5779b0
[3.13] gh-121160: Note that readline libraries using different histor…https://github.com/python/cpython/commit/838025bb865615dbbc5abdfc988fea7845f23574
gh-121160https://github.com/python/cpython/issues/121160
838025bhttps://github.com/python/cpython/commit/838025bb865615dbbc5abdfc988fea7845f23574
[3.12] gh-121160: Note that readline libraries using different histor…https://github.com/python/cpython/commit/e80497c9cd90e76bbe4c83ae82e39a52c2293077
gh-121160https://github.com/python/cpython/issues/121160
e80497chttps://github.com/python/cpython/commit/e80497c9cd90e76bbe4c83ae82e39a52c2293077
https://github.com/encukou
encukouhttps://github.com/encukou
on Jul 19, 2024https://github.com/python/cpython/issues/121160#issuecomment-2239282125
encukouhttps://github.com/encukou
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 19, 2024https://github.com/python/cpython/issues/121160#event-13575321046
https://github.com/whitequark
whitequarkhttps://github.com/whitequark
on Jul 19, 2024https://github.com/python/cpython/issues/121160#issuecomment-2239729583
halsteadhttps://github.com/halstead
on Aug 13, 2024https://github.com/python/cpython/issues/121160#event-13869006193
python3: skip readline limited history testshttps://github.com/yoctoproject/poky/commit/5b796715a937e84d1b7efb4c7b30e48fd832a3af
5b79671https://github.com/yoctoproject/poky/commit/5b796715a937e84d1b7efb4c7b30e48fd832a3af
python3: skip readline limited history testshttps://github.com/openembedded/openembedded-core/commit/20d7b78b18907dab0ca193a597b5da221b774a00
20d7b78https://github.com/openembedded/openembedded-core/commit/20d7b78b18907dab0ca193a597b5da221b774a00
python3: skip readline limited history testshttps://github.com/yoctoproject/poky/commit/c28f3a5134268543662737e39fc13b12c6df8a0d
c28f3a5https://github.com/yoctoproject/poky/commit/c28f3a5134268543662737e39fc13b12c6df8a0d
python3: skip readline limited history testshttps://github.com/openembedded/openembedded-core/commit/6c2dffdfd3c9e4bb4248be92c4e350265094dacd
6c2dffdhttps://github.com/openembedded/openembedded-core/commit/6c2dffdfd3c9e4bb4248be92c4e350265094dacd
python3: skip readline limited history testshttps://github.com/yoctoproject/poky/commit/1f8cf88eedb2055f485337f6f1f1820c3a75e4af
1f8cf88https://github.com/yoctoproject/poky/commit/1f8cf88eedb2055f485337f6f1f1820c3a75e4af
python3: skip readline limited history testshttps://github.com/yoctoproject/poky/commit/1ba06e2e54682b7f861005f7ad392bf87c2a5579
1ba06e2https://github.com/yoctoproject/poky/commit/1ba06e2e54682b7f861005f7ad392bf87c2a5579
python3: skip readline limited history testshttps://github.com/openembedded/openembedded-core/commit/32c9b4c0e6dbbae3d1eb91c65484d82f7ee596c2
32c9b4chttps://github.com/openembedded/openembedded-core/commit/32c9b4c0e6dbbae3d1eb91c65484d82f7ee596c2
https://github.com/gpshead
gpsheadhttps://github.com/gpshead
on Sep 8, 2026https://github.com/python/cpython/issues/121160#issuecomment-5579679959
#157165https://github.com/python/cpython/pull/157165
#123018https://github.com/python/cpython/issues/123018
https://github.com/encukou
encukouhttps://github.com/encukou
on Sep 8, 2026https://github.com/python/cpython/issues/121160#issuecomment-5580592719
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/121160
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/121160
topic-replRelated to the interactive shellhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-repl%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.