Skip to content

Commit

Permalink
Merge python#20
Browse files Browse the repository at this point in the history
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 <jnanjeky@unb.ca>
  • Loading branch information
bors[bot] and nanjekyejoannah authored Feb 2, 2023
2 parents ce2dc07 + 1804f7a commit 94c3759
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Lib/test/test_py3kwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,42 @@ def test_dict_inequality_comparisons(self):
w.reset()
self.assertWarning({2:3} >= {}, w, expected)

def test_dict_viewkeys(self):
expected = 'dict.viewkeys() is not supported in 3.x: use dict.keys() instead'
with check_py3k_warnings() as w:
d = {}
d.viewkeys()

def test_dict_viewvalues(self):
expected = 'dict.viewvalues() is not supported in 3.x: use dict.values() instead'
with check_py3k_warnings() as w:
d = {}
d.viewvalues()

def test_dict_viewitems(self):
expected = 'dict.viewitems() is not supported in 3.x: use dict.items() instead'
with check_py3k_warnings() as w:
d = {}
d.viewitems()

def test_dict_iterkeys(self):
expected = 'dict.iterkeys() is not supported in 3.x: use dict.keys() instead'
with check_py3k_warnings() as w:
d = {}
d.iterkeys()

def test_dict_itervalues(self):
expected = 'dict.itervalues() is not supported in 3.x: use dict.values() instead'
with check_py3k_warnings() as w:
d = {}
d.itervalues()

def test_dict_iteritems(self):
expected = 'dict.iteritems() is not supported in 3.x: use dict.items() instead'
with check_py3k_warnings() as w:
d = {}
d.iteritems()

def test_cell_inequality_comparisons(self):
expected = 'cell comparisons not supported in 3.x'
def f(x):
Expand Down
18 changes: 18 additions & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2216,18 +2216,27 @@ static PyObject *dictiter_new(PyDictObject *, PyTypeObject *);
static PyObject *
dict_iterkeys(PyDictObject *dict)
{
if (PyErr_WarnPy3k_WithFix("dict.iterkeys() is not supported in 3.x",
"use dict.keys() instead", 1) < 0)
return NULL;
return dictiter_new(dict, &PyDictIterKey_Type);
}

static PyObject *
dict_itervalues(PyDictObject *dict)
{
if (PyErr_WarnPy3k_WithFix("dict.itervalues() is not supported in 3.x",
"use dict.values() instead", 1) < 0)
return NULL;
return dictiter_new(dict, &PyDictIterValue_Type);
}

static PyObject *
dict_iteritems(PyDictObject *dict)
{
if (PyErr_WarnPy3k_WithFix("dict.iteritems() is not supported in 3.x",
"use dict.items() instead", 1) < 0)
return NULL;
return dictiter_new(dict, &PyDictIterItem_Type);
}

Expand Down Expand Up @@ -3195,6 +3204,9 @@ PyTypeObject PyDictKeys_Type = {
static PyObject *
dictkeys_new(PyObject *dict)
{
if (PyErr_WarnPy3k_WithFix("dict.viewkeys() is not supported in 3.x",
"use dict.keys() instead", 1) < 0)
return NULL;
return dictview_new(dict, &PyDictKeys_Type);
}

Expand Down Expand Up @@ -3284,6 +3296,9 @@ PyTypeObject PyDictItems_Type = {
static PyObject *
dictitems_new(PyObject *dict)
{
if (PyErr_WarnPy3k_WithFix("dict.viewitems() is not supported in 3.x",
"use dict.items() instead", 1) < 0)
return NULL;
return dictview_new(dict, &PyDictItems_Type);
}

Expand Down Expand Up @@ -3349,5 +3364,8 @@ PyTypeObject PyDictValues_Type = {
static PyObject *
dictvalues_new(PyObject *dict)
{
if (PyErr_WarnPy3k_WithFix("dict.viewvalues() is not supported in 3.x",
"use dict.values() instead", 1) < 0)
return NULL;
return dictview_new(dict, &PyDictValues_Type);
}

0 comments on commit 94c3759

Please sign in to comment.