Skip to content

The repr() of the input function is absurdly long #123149

Closed
@tritium21

Description

@tritium21

Bug report

Bug description:

>>> input
<bound method _ReadlineWrapper.input of _ReadlineWrapper(f_in=0, f_out=1, reader=ReadlineAlikeReader(console=WindowsConsole(screen=['\x1b[1;35m>>> \x1b[0minput'], height=35, width=140), buffer=['i', 'n', 'p', 'u', 't'], pos=5, ps1='>>> ', ps2='>>> ', ps3='... ', ps4='', kill_ring=[], msg='', arg=None, dirty=False, finished=True, paste_mode=False, in_bracketed_paste=False, commands={'digit_arg': <class '_pyrepl.commands.digit_arg'>, 'digit-arg': <class '_pyrepl.commands.digit_arg'>, 'clear_screen': <class '_pyrepl.commands.clear_screen'>, 'clear-screen': <class '_pyrepl.commands.clear_screen'>, 'refresh': <class '_pyrepl.commands.refresh'>, 'repaint': <class '_pyrepl.commands.repaint'>, 'kill_line': <class '_pyrepl.commands.kill_line'>, 'kill-line': <class '_pyrepl.commands.kill_line'>, 'unix_line_discard': <class '_pyrepl.commands.unix_line_discard'>, 'unix-line-discard': <class '_pyrepl.commands.unix_line_discard'>, 'unix_word_rubout': <class '_pyrepl.commands.unix_word_rubout'>, 'unix-word-rubout': <class '_pyrepl.commands.unix_word_rubout'>, 'kill_word': <class '_pyrepl.commands.kill_word'>, 'kill-word': <class '_pyrepl.commands.kill_word'>, 'backward_kill_word': <class '_pyrepl.commands.backward_kill_word'>, 'backward-kill-word': <class '_pyrepl.commands.backward_kill_word'>, 'yank': <class '_pyrepl.commands.yank'>, 'yank_pop': <class '_pyrepl.commands.yank_pop'>, 'yank-pop': <class '_pyrepl.commands.yank_pop'>, 'interrupt': <class '_pyrepl.commands.interrupt'>, 'ctrl_c': <class '_pyrepl.commands.ctrl_c'>, 'ctrl-c': <class '_pyrepl.commands.ctrl_c'>, 'suspend': <class '_pyrepl.commands.suspend'>, 'up': <class '_pyrepl.commands.up'>, 'down': <class '_pyrepl.commands.down'>, 'left': <class '_pyrepl.commands.left'>, 'right': <class '_pyrepl.commands.right'>, 'beginning_of_line': <class '_pyrepl.commands.beginning_of_line'>, 'beginning-of-line': <class '_pyrepl.commands.beginning_of_line'>, 'end_of_line': <class '_pyrepl.commands.end_of_line'>, 'end-of-line': <class '_pyrepl.commands.end_of_line'>, 'home': <class '_pyrepl.commands.home'>, 'end': <class '_pyrepl.commands.end'>, 'forward_word': <class '_pyrepl.commands.forward_word'>, 'forward-word': <class '_pyrepl.commands.forward_word'>, 'backward_word': <class '_pyrepl.commands.backward_word'>, 'backward-word': <class '_pyrepl.commands.backward_word'>, 'self_insert': <class '_pyrepl.completing_reader.self_insert'>, 'self-insert': <class '_pyrepl.completing_reader.self_insert'>, 'insert_nl': <class '_pyrepl.commands.insert_nl'>, 'insert-nl': <class '_pyrepl.commands.insert_nl'>, 'transpose_characters': <class '_pyrepl.commands.transpose_characters'>, 'transpose-characters': <class '_pyrepl.commands.transpose_characters'>, 'backspace': <class '_pyrepl.commands.backspace'>, 'delete': <class '_pyrepl.commands.delete'>, 'accept': <class '_pyrepl.commands.accept'>, 'help': <class '_pyrepl.commands.help'>, 'invalid_key': <class '_pyrepl.commands.invalid_key'>, 'invalid-key': <class '_pyrepl.commands.invalid_key'>, 'invalid_command': <class '_pyrepl.commands.invalid_command'>, 'invalid-command': <class '_pyrepl.commands.invalid_command'>, 'show_history': <class '_pyrepl.commands.show_history'>, 'show-history': <class '_pyrepl.commands.show_history'>, 'paste_mode': <class '_pyrepl.commands.paste_mode'>, 'paste-mode': <class '_pyrepl.commands.paste_mode'>, 'enable_bracketed_paste': <class '_pyrepl.commands.enable_bracketed_paste'>, 'enable-bracketed-paste': <class '_pyrepl.commands.enable_bracketed_paste'>, 'disable_bracketed_paste': <class '_pyrepl.commands.disable_bracketed_paste'>, 'disable-bracketed-paste': <class '_pyrepl.commands.disable_bracketed_paste'>, 'complete': <class '_pyrepl.completing_reader.complete'>, 'next_history': <class '_pyrepl.historical_reader.next_history'>, 'next-history': <class '_pyrepl.historical_reader.next_history'>, 'previous_history': <class '_pyrepl.historical_reader.previous_history'>, 'previous-history': <class '_pyrepl.historical_reader.previous_history'>, 'restore_history': <class '_pyrepl.historical_reader.restore_history'>, 'restore-history': <class '_pyrepl.historical_reader.restore_history'>, 'first_history': <class '_pyrepl.historical_reader.first_history'>, 'first-history': <class '_pyrepl.historical_reader.first_history'>, 'last_history': <class '_pyrepl.historical_reader.last_history'>, 'last-history': <class '_pyrepl.historical_reader.last_history'>, 'yank_arg': <class '_pyrepl.historical_reader.yank_arg'>, 'yank-arg': <class '_pyrepl.historical_reader.yank_arg'>, 'forward_history_isearch': <class '_pyrepl.historical_reader.forward_history_isearch'>, 'forward-history-isearch': <class '_pyrepl.historical_reader.forward_history_isearch'>, 'reverse_history_isearch': <class '_pyrepl.historical_reader.reverse_history_isearch'>, 'reverse-history-isearch': <class '_pyrepl.historical_reader.reverse_history_isearch'>, 'isearch_end': <class '_pyrepl.historical_reader.isearch_end'>, 'isearch-end': <class '_pyrepl.historical_reader.isearch_end'>, 'isearch_add_character': <class '_pyrepl.historical_reader.isearch_add_character'>, 'isearch-add-character': <class '_pyrepl.historical_reader.isearch_add_character'>, 'isearch_cancel': <class '_pyrepl.historical_reader.isearch_cancel'>, 'isearch-cancel': <class '_pyrepl.historical_reader.isearch_cancel'>, 'isearch_backspace': <class '_pyrepl.historical_reader.isearch_backspace'>, 'isearch-backspace': <class '_pyrepl.historical_reader.isearch_backspace'>, 'isearch_forwards': <class '_pyrepl.historical_reader.isearch_forwards'>, 'isearch-forwards': <class '_pyrepl.historical_reader.isearch_forwards'>, 'isearch_backwards': <class '_pyrepl.historical_reader.isearch_backwards'>, 'isearch-backwards': <class '_pyrepl.historical_reader.isearch_backwards'>, 'operate_and_get_next': <class '_pyrepl.historical_reader.operate_and_get_next'>, 'operate-and-get-next': <class '_pyrepl.historical_reader.operate_and_get_next'>, 'maybe_accept': <class '_pyrepl.readline.maybe_accept'>, 'maybe-accept': <class '_pyrepl.readline.maybe_accept'>, 'backspace_dedent': <class '_pyrepl.readline.backspace_dedent'>, 'backspace-dedent': <class '_pyrepl.readline.backspace_dedent'>}, last_command=<class '_pyrepl.readline.maybe_accept'>, syntax_table={'\x00': 2, '\x01': 2, '\x02': 2, '\x03': 2, '\x04': 2, '\x05': 2, '\x06': 2, '\x07': 2, '\x08': 2, '\t': 2, '\n': 0, '\x0b': 2, '\x0c': 2, '\r': 2, '\x0e': 2, '\x0f': 2, '\x10': 2, '\x11': 2, '\x12': 2, '\x13': 2, '\x14': 2, '\x15': 2, '\x16': 2, '\x17': 2, '\x18': 2, '\x19': 2, '\x1a': 2, '\x1b': 2, '\x1c': 2, '\x1d': 2, '\x1e': 2, '\x1f': 2, ' ': 0, '!': 2, '"': 2, '#': 2, '$': 2, '%': 2, '&': 2, "'": 2, '(': 2, ')': 2, '*': 2, '+': 2, ',': 2, '-': 2, '.': 2, '/': 2, '0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1, ':': 2, ';': 2, '<': 2, '=': 2, '>': 2, '?': 2, '@': 2, 'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1, 'F': 1, 'G': 1, 'H': 1, 'I': 1, 'J': 1, 'K': 1, 'L': 1, 'M': 1, 'N': 1, 'O': 1, 'P': 1, 'Q': 1, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 1, 'W': 1, 'X': 1, 'Y': 1, 'Z': 1, '[': 2, '\\': 2, ']': 2, '^': 2, '_': 2, '`': 2, 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1, 'h': 1, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1, 'o': 1, 'p': 1, 'q': 1, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1, '{': 2, '|': 2, '}': 2, '~': 2, '\x7f': 2, '\x80': 2, '\x81': 2, '\x82': 2, '\x83': 2, '\x84': 2, '\x85': 2, '\x86': 2, '\x87': 2, '\x88': 2, '\x89': 2, '\x8a': 2, '\x8b': 2, '\x8c': 2, '\x8d': 2, '\x8e': 2, '\x8f': 2, '\x90': 2, '\x91': 2, '\x92': 2, '\x93': 2, '\x94': 2, '\x95': 2, '\x96': 2, '\x97': 2, '\x98': 2, '\x99': 2, '\x9a': 2, '\x9b': 2, '\x9c': 2, '\x9d': 2, '\x9e': 2, '\x9f': 2, '\xa0': 2, '¡': 2, '¢': 2, '£': 2, '¤': 2, '¥': 2, '¦': 2, '§': 2, '¨': 2, '©': 2, 'ª': 1, '«': 2, '¬': 2, '\xad': 2, '®': 2, '¯': 2, '°': 2, '±': 2, '²': 1, '³': 1, '´': 2, 'µ': 1, '¶': 2, '·': 2, '¸': 2, '¹': 1, 'º': 1, '»': 2, '¼': 1, '½': 1, '¾': 1, '¿': 2, 'À': 1, 'Á': 1, 'Â': 1, 'Ã': 1, 'Ä': 1, 'Å': 1, 'Æ': 1, 'Ç': 1, 'È': 1, 'É': 1, 'Ê': 1, 'Ë': 1, 'Ì': 1, 'Í': 1, 'Î': 1, 'Ï': 1, 'Ð': 1, 'Ñ': 1, 'Ò': 1, 'Ó': 1, 'Ô': 1, 'Õ': 1, 'Ö': 1, '×': 2, 'Ø': 1, 'Ù': 1, 'Ú': 1, 'Û': 1, 'Ü': 1, 'Ý': 1, 'Þ': 1, 'ß': 1, 'à': 1, 'á': 1, 'â': 1, 'ã': 1, 'ä': 1, 'å': 1, 'æ': 1, 'ç': 1, 'è': 1, 'é': 1, 'ê': 1, 'ë': 1, 'ì': 1, 'í': 1, 'î': 1, 'ï': 1, 'ð': 1, 'ñ': 1, 'ò': 1, 'ó': 1, 'ô': 1, 'õ': 1, 'ö': 1, '÷': 2, 'ø': 1, 'ù': 1, 'ú': 1, 'û': 1, 'ü': 1, 'ý': 1, 'þ': 1, 'ÿ': 1}, keymap=(('\\C-a', 'beginning-of-line'), ('\\C-b', 'left'), ('\\C-c', 'interrupt'), ('\\C-d', 'delete'), ('\\C-e', 'end-of-line'), ('\\C-f', 'right'), ('\\C-g', 'cancel'), ('\\C-h', 'backspace'), ('\\C-j', 'accept'), ('\\<return>', 'accept'), ('\\C-k', 'kill-line'), ('\\C-l', 'clear-screen'), ('\\C-m', 'accept'), ('\\C-t', 'transpose-characters'), ('\\C-u', 'unix-line-discard'), ('\\C-w', 'unix-word-rubout'), ('\\C-x\\C-u', 'upcase-region'), ('\\C-y', 'yank'), ('\\C-z', 'suspend'), ('\\M-b', 'backward-word'), ('\\M-c', 'capitalize-word'), ('\\M-d', 'kill-word'), ('\\M-f', 'forward-word'), ('\\M-l', 'downcase-word'), ('\\M-t', 'transpose-words'), ('\\M-u', 'upcase-word'), ('\\M-y', 'yank-pop'), ('\\M--', 'digit-arg'), ('\\M-0', 'digit-arg'), ('\\M-1', 'digit-arg'), ('\\M-2', 'digit-arg'), ('\\M-3', 'digit-arg'), ('\\M-4', 'digit-arg'), ('\\M-5', 'digit-arg'), ('\\M-6', 'digit-arg'), ('\\M-7', 'digit-arg'), ('\\M-8', 'digit-arg'), ('\\M-9', 'digit-arg'), ('\\M-\\n', 'accept'), ('\\\\', 'self-insert'), ('\\x1b[200~', 'enable_bracketed_paste'), ('\\x1b[201~', 'disable_bracketed_paste'), ('\\x03', 'ctrl-c'), (' ', 'self-insert'), ('!', 'self-insert'), ('"', 'self-insert'), ('#', 'self-insert'), ('$', 'self-insert'), ('%', 'self-insert'), ('&', 'self-insert'), ("'", 'self-insert'), ('(', 'self-insert'), (')', 'self-insert'), ('*', 'self-insert'), ('+', 'self-insert'), (',', 'self-insert'), ('-', 'self-insert'), ('.', 'self-insert'), ('/', 'self-insert'), ('0', 'self-insert'), ('1', 'self-insert'), ('2', 'self-insert'), ('3', 'self-insert'), ('4', 'self-insert'), ('5', 'self-insert'), ('6', 'self-insert'), ('7', 'self-insert'), ('8', 'self-insert'), ('9', 'self-insert'), (':', 'self-insert'), (';', 'self-insert'), ('<', 'self-insert'), ('=', 'self-insert'), ('>', 'self-insert'), ('?', 'self-insert'), ('@', 'self-insert'), ('A', 'self-insert'), ('B', 'self-insert'), ('C', 'self-insert'), ('D', 'self-insert'), ('E', 'self-insert'), ('F', 'self-insert'), ('G', 'self-insert'), ('H', 'self-insert'), ('I', 'self-insert'), ('J', 'self-insert'), ('K', 'self-insert'), ('L', 'self-insert'), ('M', 'self-insert'), ('N', 'self-insert'), ('O', 'self-insert'), ('P', 'self-insert'), ('Q', 'self-insert'), ('R', 'self-insert'), ('S', 'self-insert'), ('T', 'self-insert'), ('U', 'self-insert'), ('V', 'self-insert'), ('W', 'self-insert'), ('X', 'self-insert'), ('Y', 'self-insert'), ('Z', 'self-insert'), ('[', 'self-insert'), (']', 'self-insert'), ('^', 'self-insert'), ('_', 'self-insert'), ('`', 'self-insert'), ('a', 'self-insert'), ('b', 'self-insert'), ('c', 'self-insert'), ('d', 'self-insert'), ('e', 'self-insert'), ('f', 'self-insert'), ('g', 'self-insert'), ('h', 'self-insert'), ('i', 'self-insert'), ('j', 'self-insert'), ('k', 'self-insert'), ('l', 'self-insert'), ('m', 'self-insert'), ('n', 'self-insert'), ('o', 'self-insert'), ('p', 'self-insert'), ('q', 'self-insert'), ('r', 'self-insert'), ('s', 'self-insert'), ('t', 'self-insert'), ('u', 'self-insert'), ('v', 'self-insert'), ('w', 'self-insert'), ('x', 'self-insert'), ('y', 'self-insert'), ('z', 'self-insert'), ('{', 'self-insert'), ('|', 'self-insert'), ('}', 'self-insert'), ('~', 'self-insert'), ('ª', 'self-insert'), ('µ', 'self-insert'), ('º', 'self-insert'), ('À', 'self-insert'), ('Á', 'self-insert'), ('Â', 'self-insert'), ('Ã', 'self-insert'), ('Ä', 'self-insert'), ('Å', 'self-insert'), ('Æ', 'self-insert'), ('Ç', 'self-insert'), ('È', 'self-insert'), ('É', 'self-insert'), ('Ê', 'self-insert'), ('Ë', 'self-insert'), ('Ì', 'self-insert'), ('Í', 'self-insert'), ('Î', 'self-insert'), ('Ï', 'self-insert'), ('Ð', 'self-insert'), ('Ñ', 'self-insert'), ('Ò', 'self-insert'), ('Ó', 'self-insert'), ('Ô', 'self-insert'), ('Õ', 'self-insert'), ('Ö', 'self-insert'), ('Ø', 'self-insert'), ('Ù', 'self-insert'), ('Ú', 'self-insert'), ('Û', 'self-insert'), ('Ü', 'self-insert'), ('Ý', 'self-insert'), ('Þ', 'self-insert'), ('ß', 'self-insert'), ('à', 'self-insert'), ('á', 'self-insert'), ('â', 'self-insert'), ('ã', 'self-insert'), ('ä', 'self-insert'), ('å', 'self-insert'), ('æ', 'self-insert'), ('ç', 'self-insert'), ('è', 'self-insert'), ('é', 'self-insert'), ('ê', 'self-insert'), ('ë', 'self-insert'), ('ì', 'self-insert'), ('í', 'self-insert'), ('î', 'self-insert'), ('ï', 'self-insert'), ('ð', 'self-insert'), ('ñ', 'self-insert'), ('ò', 'self-insert'), ('ó', 'self-insert'), ('ô', 'self-insert'), ('õ', 'self-insert'), ('ö', 'self-insert'), ('ø', 'self-insert'), ('ù', 'self-insert'), ('ú', 'self-insert'), ('û', 'self-insert'), ('ü', 'self-insert'), ('ý', 'self-insert'), ('þ', 'self-insert'), ('ÿ', 'self-insert'), ('\\<up>', 'up'), ('\\<down>', 'down'), ('\\<left>', 'left'), ('\\C-\\<left>', 'backward-word'), ('\\<right>', 'right'), ('\\C-\\<right>', 'forward-word'), ('\\<delete>', 'delete'), ('\\<backspace>', 'backspace'), ('\\M-\\<backspace>', 'backward-kill-word'), ('\\<end>', 'end-of-line'), ('\\<home>', 'beginning-of-line'), ('\\<f1>', 'help'), ('\\<f2>', 'show-history'), ('\\<f3>', 'paste-mode'), ('\\EOF', 'end'), ('\\EOH', 'home'), ('\\t', 'complete'), ('\\C-n', 'next-history'), ('\\C-p', 'previous-history'), ('\\C-o', 'operate-and-get-next'), ('\\C-r', 'reverse-history-isearch'), ('\\C-s', 'forward-history-isearch'), ('\\M-r', 'restore-history'), ('\\M-.', 'yank-arg'), ('\\<page down>', 'last-history'), ('\\<page up>', 'first-history'), ('\\n', 'maybe-accept'), ('\\<backspace>', 'backspace-dedent')), input_trans=<_pyrepl.input.KeymapTranslator object at 0x0000015EC6269400s=[], can_colorize=True, last_refresh_cache=Reader.RefreshCache(in_bracketed_paste=False, screen=['\x1b[1;35m>>> \x1b[0minput'], screeninfo=le=False, cmpltn_message_visible=False, cmpltn_menu_end=0, cmpltn_menu_choices=[], history=['vars()', 'vars().foo = 1', 'globals()', 'locals()', 'locals() is globals() is vars()', 'foo = 1', 'def fun():\n    bar = 2\n    print(vars())\n    ', 'fun()', 'def fun():\n    bar = 2\n    print(dict(globals()).update(locals()))', 'fun()', 'def fun():\n    bar = 2\n    print(dict(**globals(), **locals()))', 'fun()', 'def fun():\n    bar = 2\n    print(dict(**__builtins__, **globals(), **locals()))', 'fun()', 'def fun():\n    bar = 2\n    print(dict(**vars(__builtins__), **globals(), **locals()))', 'fun()', 'def fun():\n    bar = 2\n    print(vars(__builtins__) | globals() | locals())', 'fun()', 'bar = 1', 'fun()', 'def fun():\n    bar = 2\n    print(vars(__builtins__) | globals() | locals())', 'fun()', 'for k, v in (vars(__builtins__) | globals() | locals()).items():\n    print(f"{k}\\n{v}\\n")\n    ', 'input'], historyi=23, next_history=None, transient_history={}, isearch_term='', isearch_direction='', isearch_start=(0, 0), isearch_trans=<_pyrepl.input.KeymapTranslator object at 0x0000015EC4963ED0>, yank_arg_i=0, yank_arg_yanked='', config=ReadlineConfig(readline_completer=<bound method Completer.complete of <rlcompleter.Completer object at 0x0000015EC6269940>>, completer_delims=frozenset({'$', '{', '"', '#', ',', ')', '!', '|', '%', '+', '~', ':', '?', '@', "'", '*', '^', '-', '(', '\t', '[', '}', '=', ' ', '/', '>', '\n', ';', '\\', '&', '`', '<', ']'})), more_lines=None, last_used_indentation='    '), saved_history_length=-1, startup_hook=None, config=ReadlineConfig(readline_completer=<bound method Completer.complete of <rlcompleter.Completer object at 0x0000015EC6269940>>, completer_delims=frozenset({'$', '{', '"', '#', ',', ')', '!', '|', '%', '+', '~', ':', '?', '@', "'", '*', '^', '-', '(', '\t', '[', '}', '=', ' ', '/', '>', '\n', ';', '\\', '&', '`', '<', ']'})))>
>>> 

Yes, this is one incredibly long line.

This is bound to trip up a new user, and provides little of value to an experienced user. Its worth pruning the repr.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Activity

picnixz

picnixz commented on Aug 19, 2024

@picnixz
Member

The reason is that _ReadlineWrapper is a dataclass and this one is responsible for the long __repr__. I'll work on a patch.

PS: Actually all reader classes are dataclasses so all their fields are included...

self-assigned this
on Aug 19, 2024
SnoopJ

SnoopJ commented on Aug 19, 2024

@SnoopJ
Contributor

@picnixz I just submitted a patch for this issue, as follow-up to some discussion on #python on Libera.chat IRC

removed their assignment
on Aug 19, 2024
changed the title The repr() of the input function is absrudly long The repr() of the input function is absurdly long on Aug 19, 2024
added
3.13bugs and security fixes
3.14new features, bugs and security fixes
on Aug 19, 2024
added a commit that references this issue on Aug 19, 2024

gh-123149: Suppress verbose repr in new REPL (#123151)

833c58b
added a commit that references this issue on Aug 19, 2024

pythongh-123149: Suppress verbose repr in new REPL (pythonGH-123151)

added a commit that references this issue on Aug 19, 2024

[3.13] gh-123149: Suppress verbose repr in new REPL (GH-123151) (#123157

98c7196

2 remaining items

Loading
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

    3.13bugs and security fixes3.14new features, bugs and security fixestopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Participants

    @tritium21@SnoopJ@picnixz@Eclips4

    Issue actions

      The repr() of the input function is absurdly long · Issue #123149 · python/cpython