Skip to content

Commit 6f4b242

Browse files
authored
gh-96905: In IDLE code, stop redefining built-ins 'dict' and 'object' (#114227)
Prefix 'dict' with 'o', 'g', or 'l' for 'object', 'global', or 'local'. Suffix 'object' with '_'.
1 parent 8cda720 commit 6f4b242

File tree

8 files changed

+45
-42
lines changed

8 files changed

+45
-42
lines changed

Lib/idlelib/News3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Released on 2024-10-xx
44
=========================
55

66

7+
gh-96905: In idlelib code, stop redefining built-ins 'dict' and 'object'.
8+
79
gh-72284: Improve the lists of features, editor key bindings,
810
and shell key bingings in the IDLE doc.
911

Lib/idlelib/debugger.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ def show_source(self, index):
508508
class NamespaceViewer:
509509
"Global/local namespace viewer for debugger GUI."
510510

511-
def __init__(self, master, title, dict=None):
511+
def __init__(self, master, title, odict=None): # XXX odict never passed.
512512
width = 0
513513
height = 40
514-
if dict:
515-
height = 20*len(dict) # XXX 20 == observed height of Entry widget
514+
if odict:
515+
height = 20*len(odict) # XXX 20 == observed height of Entry widget
516516
self.master = master
517517
self.title = title
518518
import reprlib
@@ -533,24 +533,24 @@ def __init__(self, master, title, dict=None):
533533
canvas["yscrollcommand"] = vbar.set
534534
self.subframe = subframe = Frame(canvas)
535535
self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw")
536-
self.load_dict(dict)
536+
self.load_dict(odict)
537537

538-
dict = -1
538+
prev_odict = -1 # Needed for initial comparison below.
539539

540-
def load_dict(self, dict, force=0, rpc_client=None):
541-
if dict is self.dict and not force:
540+
def load_dict(self, odict, force=0, rpc_client=None):
541+
if odict is self.prev_odict and not force:
542542
return
543543
subframe = self.subframe
544544
frame = self.frame
545545
for c in list(subframe.children.values()):
546546
c.destroy()
547-
self.dict = None
548-
if not dict:
547+
self.prev_odict = None
548+
if not odict:
549549
l = Label(subframe, text="None")
550550
l.grid(row=0, column=0)
551551
else:
552552
#names = sorted(dict)
553-
###
553+
#
554554
# Because of (temporary) limitations on the dict_keys type (not yet
555555
# public or pickleable), have the subprocess to send a list of
556556
# keys, not a dict_keys object. sorted() will take a dict_keys
@@ -560,12 +560,12 @@ def load_dict(self, dict, force=0, rpc_client=None):
560560
# interpreter gets into a loop requesting non-existing dict[0],
561561
# dict[1], dict[2], etc from the debugger_r.DictProxy.
562562
# TODO recheck above; see debugger_r 159ff, debugobj 60.
563-
keys_list = dict.keys()
563+
keys_list = odict.keys()
564564
names = sorted(keys_list)
565-
###
565+
566566
row = 0
567567
for name in names:
568-
value = dict[name]
568+
value = odict[name]
569569
svalue = self.repr.repr(value) # repr(value)
570570
# Strip extra quotes caused by calling repr on the (already)
571571
# repr'd value sent across the RPC interface:
@@ -577,7 +577,7 @@ def load_dict(self, dict, force=0, rpc_client=None):
577577
l.insert(0, svalue)
578578
l.grid(row=row, column=1, sticky="nw")
579579
row = row+1
580-
self.dict = dict
580+
self.prev_odict = odict
581581
# XXX Could we use a <Configure> callback for the following?
582582
subframe.update_idletasks() # Alas!
583583
width = subframe.winfo_reqwidth()

Lib/idlelib/debugger_r.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ def frame_attr(self, fid, name):
125125

126126
def frame_globals(self, fid):
127127
frame = frametable[fid]
128-
dict = frame.f_globals
129-
did = id(dict)
130-
dicttable[did] = dict
128+
gdict = frame.f_globals
129+
did = id(gdict)
130+
dicttable[did] = gdict
131131
return did
132132

133133
def frame_locals(self, fid):
134134
frame = frametable[fid]
135-
dict = frame.f_locals
136-
did = id(dict)
137-
dicttable[did] = dict
135+
ldict = frame.f_locals
136+
did = id(ldict)
137+
dicttable[did] = ldict
138138
return did
139139

140140
def frame_code(self, fid):
@@ -158,20 +158,17 @@ def code_filename(self, cid):
158158

159159
def dict_keys(self, did):
160160
raise NotImplementedError("dict_keys not public or pickleable")
161-
## dict = dicttable[did]
162-
## return dict.keys()
161+
## return dicttable[did].keys()
163162

164-
### Needed until dict_keys is type is finished and pickealable.
163+
### Needed until dict_keys type is finished and pickleable.
164+
# xxx finished. pickleable?
165165
### Will probably need to extend rpc.py:SocketIO._proxify at that time.
166166
def dict_keys_list(self, did):
167-
dict = dicttable[did]
168-
return list(dict.keys())
167+
return list(dicttable[did].keys())
169168

170169
def dict_item(self, did, key):
171-
dict = dicttable[did]
172-
value = dict[key]
173-
value = reprlib.repr(value) ### can't pickle module 'builtins'
174-
return value
170+
value = dicttable[did][key]
171+
return reprlib.repr(value) # Can't pickle module 'builtins'.
175172

176173
#----------end class IdbAdapter----------
177174

Lib/idlelib/debugobj.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Define tree items for debug stackviewer, which is only user.
2+
"""
13
# XXX TO DO:
24
# - popup menu
35
# - support partial or total redisplay
@@ -17,9 +19,9 @@
1719
myrepr.maxother = 100
1820

1921
class ObjectTreeItem(TreeItem):
20-
def __init__(self, labeltext, object, setfunction=None):
22+
def __init__(self, labeltext, object_, setfunction=None):
2123
self.labeltext = labeltext
22-
self.object = object
24+
self.object = object_
2325
self.setfunction = setfunction
2426
def GetLabelText(self):
2527
return self.labeltext
@@ -51,8 +53,8 @@ def GetSubList(self):
5153
item = make_objecttreeitem(
5254
str(key) + " =",
5355
value,
54-
lambda value, key=key, object=self.object:
55-
setattr(object, key, value))
56+
lambda value, key=key, object_=self.object:
57+
setattr(object_, key, value))
5658
sublist.append(item)
5759
return sublist
5860

@@ -85,8 +87,8 @@ def GetSubList(self):
8587
value = self.object[key]
8688
except KeyError:
8789
continue
88-
def setfunction(value, key=key, object=self.object):
89-
object[key] = value
90+
def setfunction(value, key=key, object_=self.object):
91+
object_[key] = value
9092
item = make_objecttreeitem(f"{key!r}:", value, setfunction)
9193
sublist.append(item)
9294
return sublist
@@ -111,13 +113,13 @@ def keys(self):
111113
type: ClassTreeItem,
112114
}
113115

114-
def make_objecttreeitem(labeltext, object, setfunction=None):
115-
t = type(object)
116+
def make_objecttreeitem(labeltext, object_, setfunction=None):
117+
t = type(object_)
116118
if t in dispatch:
117119
c = dispatch[t]
118120
else:
119121
c = ObjectTreeItem
120-
return c(labeltext, object, setfunction)
122+
return c(labeltext, object_, setfunction)
121123

122124

123125
def _debug_object_browser(parent): # htest #

Lib/idlelib/idle_test/test_calltip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SB: __call__ = None
7979
tiptest(list.append, '(self, object, /)' + append_doc)
8080
tiptest(List.append, '(self, object, /)' + append_doc)
8181
tiptest([].append, '(object, /)' + append_doc)
82+
# The use of 'object' above matches the signature text.
8283

8384
tiptest(types.MethodType,
8485
'(function, instance, /)\n'

Lib/idlelib/rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def debug(self, *args):
158158
s = s + " " + str(a)
159159
print(s, file=sys.__stderr__)
160160

161-
def register(self, oid, object):
162-
self.objtable[oid] = object
161+
def register(self, oid, object_):
162+
self.objtable[oid] = object_
163163

164164
def unregister(self, oid):
165165
try:

Lib/idlelib/stackviewer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def GetSubList(self):
106106
value = self.object[key]
107107
except KeyError:
108108
continue
109-
def setfunction(value, key=key, object=self.object):
110-
object[key] = value
109+
def setfunction(value, key=key, object_=self.object):
110+
object_[key] = value
111111
item = make_objecttreeitem(key + " =", value, setfunction)
112112
sublist.append(item)
113113
return sublist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In idlelib code, stop redefining built-ins 'dict' and 'object'.

0 commit comments

Comments
 (0)