Skip to content

Commit 94c3759

Browse files
Merge python#20
20: Warn for missing dict features r=ltratt a=nanjekyejoannah I warn for several features. i looked at this code earlier and had an illusion, for some reason I thought we had these covered until I ran against twisted. Co-authored-by: Joannah Nanjekye <[email protected]>
2 parents ce2dc07 + 1804f7a commit 94c3759

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Lib/test/test_py3kwarn.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,42 @@ def test_dict_inequality_comparisons(self):
112112
w.reset()
113113
self.assertWarning({2:3} >= {}, w, expected)
114114

115+
def test_dict_viewkeys(self):
116+
expected = 'dict.viewkeys() is not supported in 3.x: use dict.keys() instead'
117+
with check_py3k_warnings() as w:
118+
d = {}
119+
d.viewkeys()
120+
121+
def test_dict_viewvalues(self):
122+
expected = 'dict.viewvalues() is not supported in 3.x: use dict.values() instead'
123+
with check_py3k_warnings() as w:
124+
d = {}
125+
d.viewvalues()
126+
127+
def test_dict_viewitems(self):
128+
expected = 'dict.viewitems() is not supported in 3.x: use dict.items() instead'
129+
with check_py3k_warnings() as w:
130+
d = {}
131+
d.viewitems()
132+
133+
def test_dict_iterkeys(self):
134+
expected = 'dict.iterkeys() is not supported in 3.x: use dict.keys() instead'
135+
with check_py3k_warnings() as w:
136+
d = {}
137+
d.iterkeys()
138+
139+
def test_dict_itervalues(self):
140+
expected = 'dict.itervalues() is not supported in 3.x: use dict.values() instead'
141+
with check_py3k_warnings() as w:
142+
d = {}
143+
d.itervalues()
144+
145+
def test_dict_iteritems(self):
146+
expected = 'dict.iteritems() is not supported in 3.x: use dict.items() instead'
147+
with check_py3k_warnings() as w:
148+
d = {}
149+
d.iteritems()
150+
115151
def test_cell_inequality_comparisons(self):
116152
expected = 'cell comparisons not supported in 3.x'
117153
def f(x):

Objects/dictobject.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,18 +2216,27 @@ static PyObject *dictiter_new(PyDictObject *, PyTypeObject *);
22162216
static PyObject *
22172217
dict_iterkeys(PyDictObject *dict)
22182218
{
2219+
if (PyErr_WarnPy3k_WithFix("dict.iterkeys() is not supported in 3.x",
2220+
"use dict.keys() instead", 1) < 0)
2221+
return NULL;
22192222
return dictiter_new(dict, &PyDictIterKey_Type);
22202223
}
22212224

22222225
static PyObject *
22232226
dict_itervalues(PyDictObject *dict)
22242227
{
2228+
if (PyErr_WarnPy3k_WithFix("dict.itervalues() is not supported in 3.x",
2229+
"use dict.values() instead", 1) < 0)
2230+
return NULL;
22252231
return dictiter_new(dict, &PyDictIterValue_Type);
22262232
}
22272233

22282234
static PyObject *
22292235
dict_iteritems(PyDictObject *dict)
22302236
{
2237+
if (PyErr_WarnPy3k_WithFix("dict.iteritems() is not supported in 3.x",
2238+
"use dict.items() instead", 1) < 0)
2239+
return NULL;
22312240
return dictiter_new(dict, &PyDictIterItem_Type);
22322241
}
22332242

@@ -3195,6 +3204,9 @@ PyTypeObject PyDictKeys_Type = {
31953204
static PyObject *
31963205
dictkeys_new(PyObject *dict)
31973206
{
3207+
if (PyErr_WarnPy3k_WithFix("dict.viewkeys() is not supported in 3.x",
3208+
"use dict.keys() instead", 1) < 0)
3209+
return NULL;
31983210
return dictview_new(dict, &PyDictKeys_Type);
31993211
}
32003212

@@ -3284,6 +3296,9 @@ PyTypeObject PyDictItems_Type = {
32843296
static PyObject *
32853297
dictitems_new(PyObject *dict)
32863298
{
3299+
if (PyErr_WarnPy3k_WithFix("dict.viewitems() is not supported in 3.x",
3300+
"use dict.items() instead", 1) < 0)
3301+
return NULL;
32873302
return dictview_new(dict, &PyDictItems_Type);
32883303
}
32893304

@@ -3349,5 +3364,8 @@ PyTypeObject PyDictValues_Type = {
33493364
static PyObject *
33503365
dictvalues_new(PyObject *dict)
33513366
{
3367+
if (PyErr_WarnPy3k_WithFix("dict.viewvalues() is not supported in 3.x",
3368+
"use dict.values() instead", 1) < 0)
3369+
return NULL;
33523370
return dictview_new(dict, &PyDictValues_Type);
33533371
}

0 commit comments

Comments
 (0)