[3.12] gh-103737: IDLE - Remove unneeded .keys() for dict iteration (GH-110960) (#111026)

gh-103737: IDLE - Remove unneeded .keys() for dict iteration (GH-110960)

Add comments where .keys() is needed.
Leave debugger usages along because situation is unclear as indicated in expanded comment.
Most testing is manual.
(cherry picked from commit baefbb21d9)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2023-10-18 11:05:08 +02:00 committed by GitHub
parent 577a8fb72b
commit b8ce5d9c17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 26 deletions

View file

@ -747,10 +747,11 @@ class ModifiedInterpreter(InteractiveInterpreter):
self.tkconsole.open_stack_viewer()
def checklinecache(self):
c = linecache.cache
for key in list(c.keys()):
"Remove keys other than '<pyshell#n>'."
cache = linecache.cache
for key in list(cache): # Iterate list because mutate cache.
if key[:1] + key[-1:] != "<>":
del c[key]
del cache[key]
def runcommand(self, code):
"Run the code without invoking the debugger"