python / python/cpython

Readline: importting `pathlib` breaks libedit `readline.read_init_file` when `.editrc`'s comments are longer than 20 characters

Open
#117,704 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Environment

macOS Sonoma 14.3.1
Python 3.12.2
Libedit readline (I tested with my Linux VM and seems that the same bug doesn't appear for libreadline)

Bug Description

When reading .editrc for libedit readline with readline.read_init_file in python startup script, if both these two conditions are true:

  1. Python startup script imports pathlib
  2. .editrc contains comments with more than 21 characters

.editrc will not be applied to Python REPL. Manually typing readline.read_init_file again in REPL works though.

How to Reproduce the Bug

  1. Create a minimal python startup script with these lines:
import pathlib
import readline

readline.read_init_file('/path/to/your/editrc')
  1. Create a minimal .editrc to test if it is applied (I'm using 1's and bind -v here but you can change them to whatever you want, as long as the comment exceeds 20 characters):
#11111111111111111111

bind -v
  1. Open your terminal and test whether Vi mode is applied.
  2. (extra) If you break the comment in .editrc into multiple lines, but not adding any 1, it still breaks:
#11111111
#111111111111

bind -v

or

#1111
#1111

bind -v

#1111111
#11111
CPython versions tested on:

3.12

Operating systems tested on:

Linux, macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the Python startup script, pathlib, readline.read_init_file, and a .editrc containing comments longer than 20 characters on libedit. Trace the readline.read_init_file path and confirm that the .editrc settings are applied when pathlib is imported; completion means the reproduction no longer fails while the existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.