Skip to content

Modernize Code In IDLELib Editor Backspace (and potentially deprecate handling of tabs in IDLE) #136556

Open
@johnzhou721

Description

@johnzhou721

In #136061,

cpython/Lib/idlelib/editor.py

Lines 1365 to 1385 in 561212a

# Ick. It may require *inserting* spaces if we back up over a
# tab character! This is written to be clear, not fast.
tabwidth = self.tabwidth
have = len(chars.expandtabs(tabwidth))
assert have > 0
want = ((have - 1) // self.indentwidth) * self.indentwidth
# Debug prompt is multilined....
ncharsdeleted = 0
while True:
chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1
have = len(chars.expandtabs(tabwidth))
if have <= want or chars[-1] not in " \t":
break
text.undo_block_start()
text.delete("insert-%dc" % ncharsdeleted, "insert")
if have < want:
text.insert("insert", ' ' * (want - have),
self.user_input_insert_tags)
text.undo_block_stop()
return "break"
is mentioned as an area of code with quadratic complexity, which may lead to performance issues; though this is unlikely to be of large impact in practice because attackers with the ability to get a huge file loaded and/or modify configuration files to change the tab width can do much worse things than getting IDLE to hang on hitting backspace.

However, the complexity there comes from a loop which handles situations (files with tabs) that either cannot or should not occur; in the current default IDLE, you can't put tabs, and a space after a tab should just be deleted in a file coming from elsewhere as in indicated in #134874 (comment). Therefore, simplifying the function specification and/or deprecating IDLE to handle tabs (which we should do) will allow elimination of this piece of obsolete code, as indicated in #136061 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-IDLEtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions