Skip to content

Press <Tab> at the beginning of the line #64

Open

Description

@empyrealtear

The console throw some error when I try to press <Tab> at the beginning of the line.

>>> Readline internal error
Traceback (most recent call last):
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\rlmain.py", line 578, in readline
    self._readline_from_keyboard()
8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\rlmain.py", line 543, in _readline_from_keyboard
    if self._readline_from_keyboard_poll():
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\rlmain.py", line 563, in _readline_from_keyboard_poll
    result = self.mode.process_keyevent(event.keyinfo)
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\modes\emacs.py", line 243, in process_keyevent
    r = self.process_keyevent_queue[-1](keyinfo)
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\modes\emacs.py", line 286, in _process_keyevent
    r = dispatch_func(keyinfo)
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\modes\basemode.py", line 268, in complete
    completions = self._get_completions()
  File "C:\Users\24658\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyreadline\modes\basemode.py", line 210, in _get_completions
    r = self.completer(ensure_unicode(text), i)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\rlcompleter.py", line 80, in complete
    readline.redisplay()
AttributeError: module 'readline' has no attribute 'redisplay'

for this, I edit some source code. There will insert a string filled by space when press at beginning of the line.

  • First, open py script named basemode.py
  • Second, check text;
def _get_completions(self):
    ...
        text = ensure_str(''.join(buf[self.begidx:self.endidx]))
        if (len(text) == 0):
            return
        log('complete text="%s"' % ensure_unicode(text))
    ...
  • Finally, insert text if completions
def complete(self, e): # (TAB)
    ...
    if completions:
        ...
    else:
        self._bell()
        self.insert_text('    ')

Activity

  1. changed the title [-]Press tab at the beginning of the line[/-] [+]Press <Tab> at the beginning of the line[/+] on Jul 23, 2020
  2. japython commented on Sep 22, 2020

    @japython

    I can resolve the issue, thanks to your article!

  3. eabase commented on Dec 28, 2021

    @eabase

    @empyrealtear
    I don't understand what you are editing. (What are we replacing, and where?)
    Can you please post better instructions or make a PR?

  4. eabase commented on Dec 28, 2021

    @eabase

    Ok I got it:
    You need to edit: C:\Python310\Lib\site-packages\pyreadline\modes\basemode.py:
    Adding the code (at above places)

    # at line 196
            if (len(text) == 0):
                return
    
    # at line ~272
            self.insert_text('    ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions