From 881557a0ea4cec9a7d66c96e77615a8e51f467cd Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 24 Sep 2022 14:01:00 -0400 Subject: [PATCH 1/4] gh-96905: IDLE - Stop reusing built-in names Change 'dict', 'object' to 'dict_', 'object_'. --- Lib/idlelib/debugger.py | 23 ++++++++++++----------- Lib/idlelib/debugger_r.py | 27 ++++++++++++--------------- Lib/idlelib/debugobj.py | 20 +++++++++++--------- Lib/idlelib/idle_test/test_calltip.py | 1 + Lib/idlelib/rpc.py | 4 ++-- Lib/idlelib/stackviewer.py | 4 ++-- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/Lib/idlelib/debugger.py b/Lib/idlelib/debugger.py index ccd03e46e16147..6c5042005d4ba9 100644 --- a/Lib/idlelib/debugger.py +++ b/Lib/idlelib/debugger.py @@ -457,11 +457,11 @@ def show_source(self, index): class NamespaceViewer: - def __init__(self, master, title, dict=None): + def __init__(self, master, title, dict_=None): # XXX dict_ never passed. width = 0 height = 40 - if dict: - height = 20*len(dict) # XXX 20 == observed height of Entry widget + if dict_: + height = 20*len(dict_) # XXX 20 == observed height of Entry widget self.master = master self.title = title import reprlib @@ -482,19 +482,20 @@ def __init__(self, master, title, dict=None): canvas["yscrollcommand"] = vbar.set self.subframe = subframe = Frame(canvas) self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw") - self.load_dict(dict) + self.load_dict(dict_) - dict = -1 + dict = -1 # Needed for self.dict below. - def load_dict(self, dict, force=0, rpc_client=None): - if dict is self.dict and not force: + def load_dict(self, dict_, force=0, rpc_client=None): + print(self.dict, dict_) + if dict_ is self.dict and not force: return subframe = self.subframe frame = self.frame for c in list(subframe.children.values()): c.destroy() self.dict = None - if not dict: + if not dict_: l = Label(subframe, text="None") l.grid(row=0, column=0) else: @@ -509,12 +510,12 @@ def load_dict(self, dict, force=0, rpc_client=None): # interpreter gets into a loop requesting non-existing dict[0], # dict[1], dict[2], etc from the debugger_r.DictProxy. ### - keys_list = dict.keys() + keys_list = dict_.keys() names = sorted(keys_list) ### row = 0 for name in names: - value = dict[name] + value = dict_[name] svalue = self.repr.repr(value) # repr(value) # Strip extra quotes caused by calling repr on the (already) # repr'd value sent across the RPC interface: @@ -526,7 +527,7 @@ def load_dict(self, dict, force=0, rpc_client=None): l.insert(0, svalue) l.grid(row=row, column=1, sticky="nw") row = row+1 - self.dict = dict + self.dict = dict_ # XXX Could we use a callback for the following? subframe.update_idletasks() # Alas! width = subframe.winfo_reqwidth() diff --git a/Lib/idlelib/debugger_r.py b/Lib/idlelib/debugger_r.py index 26204438858d8a..ad3355d9f82765 100644 --- a/Lib/idlelib/debugger_r.py +++ b/Lib/idlelib/debugger_r.py @@ -125,16 +125,16 @@ def frame_attr(self, fid, name): def frame_globals(self, fid): frame = frametable[fid] - dict = frame.f_globals - did = id(dict) - dicttable[did] = dict + gdict = frame.f_globals + did = id(gdict) + dicttable[did] = gdict return did def frame_locals(self, fid): frame = frametable[fid] - dict = frame.f_locals - did = id(dict) - dicttable[did] = dict + ldict = frame.f_locals + did = id(ldict) + dicttable[did] = ldict return did def frame_code(self, fid): @@ -158,20 +158,17 @@ def code_filename(self, cid): def dict_keys(self, did): raise NotImplementedError("dict_keys not public or pickleable") -## dict = dicttable[did] -## return dict.keys() +## return dicttable[did].keys() - ### Needed until dict_keys is type is finished and pickealable. + ### Needed until dict_keys type is finished and pickleable. + # xxx finished. pickleable? ### Will probably need to extend rpc.py:SocketIO._proxify at that time. def dict_keys_list(self, did): - dict = dicttable[did] - return list(dict.keys()) + return list(dicttable[did].keys()) def dict_item(self, did, key): - dict = dicttable[did] - value = dict[key] - value = reprlib.repr(value) ### can't pickle module 'builtins' - return value + value = dicttable[did][key] + return reprlib.repr(value) # Can't pickle module 'builtins'. #----------end class IdbAdapter---------- diff --git a/Lib/idlelib/debugobj.py b/Lib/idlelib/debugobj.py index 5a4c9978842035..2bf08a57525924 100644 --- a/Lib/idlelib/debugobj.py +++ b/Lib/idlelib/debugobj.py @@ -1,3 +1,5 @@ +"""Define tree items for debug stackviewer, which is only user. +""" # XXX TO DO: # - popup menu # - support partial or total redisplay @@ -17,9 +19,9 @@ myrepr.maxother = 100 class ObjectTreeItem(TreeItem): - def __init__(self, labeltext, object, setfunction=None): + def __init__(self, labeltext, object_, setfunction=None): self.labeltext = labeltext - self.object = object + self.object = object_ self.setfunction = setfunction def GetLabelText(self): return self.labeltext @@ -51,8 +53,8 @@ def GetSubList(self): item = make_objecttreeitem( str(key) + " =", value, - lambda value, key=key, object=self.object: - setattr(object, key, value)) + lambda value, key=key, object_=self.object: + setattr(object_, key, value)) sublist.append(item) return sublist @@ -85,8 +87,8 @@ def GetSubList(self): value = self.object[key] except KeyError: continue - def setfunction(value, key=key, object=self.object): - object[key] = value + def setfunction(value, key=key, object_=self.object): + object_[key] = value item = make_objecttreeitem("%r:" % (key,), value, setfunction) sublist.append(item) return sublist @@ -110,13 +112,13 @@ def keys(self): type: ClassTreeItem, } -def make_objecttreeitem(labeltext, object, setfunction=None): - t = type(object) +def make_objecttreeitem(labeltext, object_, setfunction=None): + t = type(object_) if t in dispatch: c = dispatch[t] else: c = ObjectTreeItem - return c(labeltext, object, setfunction) + return c(labeltext, object_, setfunction) def _object_browser(parent): # htest # diff --git a/Lib/idlelib/idle_test/test_calltip.py b/Lib/idlelib/idle_test/test_calltip.py index 1ccb63b9dbd65f..96c3bf33c7831a 100644 --- a/Lib/idlelib/idle_test/test_calltip.py +++ b/Lib/idlelib/idle_test/test_calltip.py @@ -76,6 +76,7 @@ class SB: __call__ = None tiptest(list.append, '(self, object, /)' + append_doc) tiptest(List.append, '(self, object, /)' + append_doc) tiptest([].append, '(object, /)' + append_doc) + # The use of 'object' above matches the signature text. tiptest(types.MethodType, '(function, instance, /)\n' diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py index 62eec84c9c8d09..ca521f94ec4917 100644 --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -158,8 +158,8 @@ def debug(self, *args): s = s + " " + str(a) print(s, file=sys.__stderr__) - def register(self, oid, object): - self.objtable[oid] = object + def register(self, oid, object_): + self.objtable[oid] = object_ def unregister(self, oid): try: diff --git a/Lib/idlelib/stackviewer.py b/Lib/idlelib/stackviewer.py index 94ffb4eff4dd26..4f514fb799c620 100644 --- a/Lib/idlelib/stackviewer.py +++ b/Lib/idlelib/stackviewer.py @@ -117,8 +117,8 @@ def GetSubList(self): value = self.object[key] except KeyError: continue - def setfunction(value, key=key, object=self.object): - object[key] = value + def setfunction(value, key=key, object_=self.object): + object_[key] = value item = make_objecttreeitem(key + " =", value, setfunction) sublist.append(item) return sublist From b2609af58d66d58ed4954bc9ed50daf8145d0a47 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 17 Jan 2024 22:31:27 -0500 Subject: [PATCH 2/4] Remove debug print --- Lib/idlelib/debugger.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/idlelib/debugger.py b/Lib/idlelib/debugger.py index 4f05ff8d085f28..748409bfe1513a 100644 --- a/Lib/idlelib/debugger.py +++ b/Lib/idlelib/debugger.py @@ -538,7 +538,6 @@ def __init__(self, master, title, dict_=None): # XXX dict_ never passed. dict = -1 # Needed for self.dict below. def load_dict(self, dict_, force=0, rpc_client=None): - print(self.dict, dict_) if dict_ is self.dict and not force: return subframe = self.subframe From 9d3f53a8e1cbb0260fec695b48165e04d227b7ea Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 17 Jan 2024 22:58:14 -0500 Subject: [PATCH 3/4] In debugger, replace 'dict_' with 'odict' --- Lib/idlelib/debugger.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/idlelib/debugger.py b/Lib/idlelib/debugger.py index 748409bfe1513a..d90dbcd11f9f61 100644 --- a/Lib/idlelib/debugger.py +++ b/Lib/idlelib/debugger.py @@ -508,11 +508,11 @@ def show_source(self, index): class NamespaceViewer: "Global/local namespace viewer for debugger GUI." - def __init__(self, master, title, dict_=None): # XXX dict_ never passed. + def __init__(self, master, title, odict=None): # XXX odict never passed. width = 0 height = 40 - if dict_: - height = 20*len(dict_) # XXX 20 == observed height of Entry widget + if odict: + height = 20*len(odict) # XXX 20 == observed height of Entry widget self.master = master self.title = title import reprlib @@ -533,19 +533,19 @@ def __init__(self, master, title, dict_=None): # XXX dict_ never passed. canvas["yscrollcommand"] = vbar.set self.subframe = subframe = Frame(canvas) self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw") - self.load_dict(dict_) + self.load_dict(odict) - dict = -1 # Needed for self.dict below. + prev_odict = -1 # Needed for initial comparison below. - def load_dict(self, dict_, force=0, rpc_client=None): - if dict_ is self.dict and not force: + def load_dict(self, odict, force=0, rpc_client=None): + if odict is self.prev_odict and not force: return subframe = self.subframe frame = self.frame for c in list(subframe.children.values()): c.destroy() - self.dict = None - if not dict_: + self.prev_odict = None + if not odict: l = Label(subframe, text="None") l.grid(row=0, column=0) else: @@ -560,12 +560,12 @@ def load_dict(self, dict_, force=0, rpc_client=None): # interpreter gets into a loop requesting non-existing dict[0], # dict[1], dict[2], etc from the debugger_r.DictProxy. # TODO recheck above; see debugger_r 159ff, debugobj 60. - keys_list = dict_.keys() + keys_list = odict.keys() names = sorted(keys_list) row = 0 for name in names: - value = dict_[name] + value = odict[name] svalue = self.repr.repr(value) # repr(value) # Strip extra quotes caused by calling repr on the (already) # repr'd value sent across the RPC interface: @@ -577,7 +577,7 @@ def load_dict(self, dict_, force=0, rpc_client=None): l.insert(0, svalue) l.grid(row=row, column=1, sticky="nw") row = row+1 - self.dict = dict_ + self.prev_odict = odict # XXX Could we use a callback for the following? subframe.update_idletasks() # Alas! width = subframe.winfo_reqwidth() From 4f169c6cf984001cd21fc7818b52f5594d3d3c69 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 17 Jan 2024 23:21:28 -0500 Subject: [PATCH 4/4] News --- Lib/idlelib/News3.txt | 2 ++ .../next/IDLE/2024-01-17-23-18-15.gh-issue-96905.UYaxoU.rst | 1 + 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2024-01-17-23-18-15.gh-issue-96905.UYaxoU.rst diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt index ee36fa7e1d5341..241b1f48e5c1d8 100644 --- a/Lib/idlelib/News3.txt +++ b/Lib/idlelib/News3.txt @@ -4,6 +4,8 @@ Released on 2024-10-xx ========================= +gh-96905: In idlelib code, stop redefining built-ins 'dict' and 'object'. + gh-72284: Improve the lists of features, editor key bindings, and shell key bingings in the IDLE doc. diff --git a/Misc/NEWS.d/next/IDLE/2024-01-17-23-18-15.gh-issue-96905.UYaxoU.rst b/Misc/NEWS.d/next/IDLE/2024-01-17-23-18-15.gh-issue-96905.UYaxoU.rst new file mode 100644 index 00000000000000..fe7dde64c7c7d5 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2024-01-17-23-18-15.gh-issue-96905.UYaxoU.rst @@ -0,0 +1 @@ +In idlelib code, stop redefining built-ins 'dict' and 'object'.