# HG changeset patch
# User ZyX <[email protected]>
# Date 1370141913 -14400
# Branch python-extended-4
# Node ID aeb6697bc6851e894681f9baad6ea9dc808c6714
# Parent 7698aef182526761915fa4c3fa02080555a1b327
Change the meaning of popitem: it should not accept any arguments
diff -r 7698aef18252 -r aeb6697bc685 runtime/doc/if_pyth.txt
--- a/runtime/doc/if_pyth.txt Sat Jun 01 23:34:09 2013 +0400
+++ b/runtime/doc/if_pyth.txt Sun Jun 02 06:58:33 2013 +0400
@@ -524,10 +524,9 @@
Remove specified key from dictionary and return
corresponding value. If key is not found and default is
given returns the default, otherwise raises KeyError.
- popitem(key)
- Remove specified key from dictionary and return a pair
- with it and the corresponding value. Returned key is a new
- object.
+ popitem()
+ Remove random key from dictionary and return (key, value)
+ pair.
has_key(key)
Check whether dictionary contains specified key, similar
to `key in dict`.
diff -r 7698aef18252 -r aeb6697bc685 src/if_py_both.h
--- a/src/if_py_both.h Sat Jun 01 23:34:09 2013 +0400
+++ b/src/if_py_both.h Sun Jun 02 06:58:33 2013 +0400
@@ -1135,17 +1135,6 @@
dictitem_free(di);
}
- if (flags & DICT_FLAG_RETURN_PAIR)
- {
- PyObject *tmp = r;
-
- if (!(r = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, tmp)))
- {
- Py_DECREF(tmp);
- return NULL;
- }
- }
-
return r;
}
@@ -1532,15 +1521,38 @@
}
static PyObject *
-DictionaryPopItem(DictionaryObject *self, PyObject *args)
-{
- PyObject *keyObject;
-
- if (!PyArg_ParseTuple(args, "O", &keyObject))
+DictionaryPopItem(DictionaryObject *self)
+{
+ hashitem_T *hi;
+ PyObject *r;
+ PyObject *valObject;
+ dictitem_T *di;
+
+ if (self->dict->dv_hashtab.ht_used == 0)
+ {
+ PyErr_SetNone(PyExc_KeyError);
return NULL;
-
- return _DictionaryItem(self, keyObject,
- DICT_FLAG_POP|DICT_FLAG_RETURN_PAIR);
+ }
+
+ hi = self->dict->dv_hashtab.ht_array;
+ while (HASHITEM_EMPTY(hi))
+ ++hi;
+
+ di = dict_lookup(hi);
+
+ if (!(valObject = ConvertToPyObject(&di->di_tv)))
+ return NULL;
+
+ if (!(r = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, valObject)))
+ {
+ Py_DECREF(valObject);
+ return NULL;
+ }
+
+ hash_remove(&self->dict->dv_hashtab, hi);
+ dictitem_free(di);
+
+ return r;
}
static PyObject *
@@ -1580,7 +1592,7 @@
{"update", (PyCFunction)DictionaryUpdate,
METH_VARARGS|METH_KEYWORDS, ""},
{"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
{"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
- {"popitem", (PyCFunction)DictionaryPopItem, METH_VARARGS,
""},
+ {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS,
""},
{"has_key", (PyCFunction)DictionaryHasKey, METH_VARARGS,
""},
{"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS,
""},
{ NULL, NULL, 0, NULL}
diff -r 7698aef18252 -r aeb6697bc685 src/testdir/test86.in
--- a/src/testdir/test86.in Sat Jun 01 23:34:09 2013 +0400
+++ b/src/testdir/test86.in Sun Jun 02 06:58:33 2013 +0400
@@ -83,7 +83,7 @@
:$put =pyeval('repr(''1'' in d)')
:$put =pyeval('repr(list(iter(d)))')
:$put =string(d)
-:$put =pyeval('repr(d.popitem(''0''))')
+:$put =pyeval('repr(d.popitem())')
:$put =pyeval('repr(d.get(''0''))')
:$put =pyeval('repr(list(iter(d)))')
:"
@@ -226,7 +226,7 @@
em('d[u"a\\0b"]=1')
em('d.pop("abc")')
-em('d.popitem("abc")')
+em('d.popitem()')
EOF
:$put =messages
:unlet messages
diff -r 7698aef18252 -r aeb6697bc685 src/testdir/test86.ok
--- a/src/testdir/test86.ok Sat Jun 01 23:34:09 2013 +0400
+++ b/src/testdir/test86.ok Sun Jun 02 06:58:33 2013 +0400
@@ -26,7 +26,7 @@
False
['0']
{'0': -1}
-('', -1L)
+('0', -1L)
None
[]
[0, 1, 2, 3]
@@ -672,7 +672,7 @@
d.update((("a", FailingMappingKey()),)):(<type
'exceptions.NotImplementedError'>, NotImplementedError())
<<< Finished
>> DictionaryPopItem
-d.popitem(1, 2):(<type 'exceptions.TypeError'>, TypeError('function takes
exactly 1 argument (2 given)',))
+d.popitem(1, 2):(<type 'exceptions.TypeError'>, TypeError('popitem() takes no
arguments (2 given)',))
>> DictionaryHasKey
d.has_key():(<type 'exceptions.TypeError'>, TypeError('function takes exactly
1 argument (0 given)',))
> List
diff -r 7698aef18252 -r aeb6697bc685 src/testdir/test87.in
--- a/src/testdir/test87.in Sat Jun 01 23:34:09 2013 +0400
+++ b/src/testdir/test87.in Sun Jun 02 06:58:33 2013 +0400
@@ -77,7 +77,7 @@
:$put =py3eval('repr(''1'' in d)')
:$put =py3eval('repr(list(iter(d)))')
:$put =string(d)
-:$put =py3eval('repr(d.popitem(''0''))')
+:$put =py3eval('repr(d.popitem())')
:$put =py3eval('repr(d.get(''0''))')
:$put =py3eval('repr(list(iter(d)))')
:"
@@ -220,7 +220,7 @@
em('d[b"a\\0b"]=1')
em('d.pop("abc")')
-em('d.popitem("abc")')
+em('d.popitem()')
EOF
:$put =messages
:unlet messages
diff -r 7698aef18252 -r aeb6697bc685 src/testdir/test87.ok
--- a/src/testdir/test87.ok Sat Jun 01 23:34:09 2013 +0400
+++ b/src/testdir/test87.ok Sun Jun 02 06:58:33 2013 +0400
@@ -26,7 +26,7 @@
False
[b'0']
{'0': -1}
-(b'', -1)
+(b'0', -1)
None
[]
[0, 1, 2, 3]
@@ -669,7 +669,7 @@
d.update((("a", FailingMappingKey()),)):(<class 'NotImplementedError'>,
NotImplementedError())
<<< Finished
>> DictionaryPopItem
-d.popitem(1, 2):(<class 'TypeError'>, TypeError('function takes exactly 1
argument (2 given)',))
+d.popitem(1, 2):(<class 'TypeError'>, TypeError('popitem() takes no arguments
(2 given)',))
>> DictionaryHasKey
d.has_key():(<class 'TypeError'>, TypeError('function takes exactly 1 argument
(0 given)',))
> List
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -cr vim.7698aef18252/runtime/doc/if_pyth.txt vim.aeb6697bc685/runtime/doc/if_pyth.txt
*** vim.7698aef18252/runtime/doc/if_pyth.txt 2013-06-02 07:00:35.502979909 +0400
--- vim.aeb6697bc685/runtime/doc/if_pyth.txt 2013-06-02 07:00:35.549979577 +0400
***************
*** 524,533 ****
Remove specified key from dictionary and return
corresponding value. If key is not found and default is
given returns the default, otherwise raises KeyError.
! popitem(key)
! Remove specified key from dictionary and return a pair
! with it and the corresponding value. Returned key is a new
! object.
has_key(key)
Check whether dictionary contains specified key, similar
to `key in dict`.
--- 524,532 ----
Remove specified key from dictionary and return
corresponding value. If key is not found and default is
given returns the default, otherwise raises KeyError.
! popitem()
! Remove random key from dictionary and return (key, value)
! pair.
has_key(key)
Check whether dictionary contains specified key, similar
to `key in dict`.
diff -cr vim.7698aef18252/src/if_py_both.h vim.aeb6697bc685/src/if_py_both.h
*** vim.7698aef18252/src/if_py_both.h 2013-06-02 07:00:35.497979945 +0400
--- vim.aeb6697bc685/src/if_py_both.h 2013-06-02 07:00:35.545979605 +0400
***************
*** 1135,1151 ****
dictitem_free(di);
}
- if (flags & DICT_FLAG_RETURN_PAIR)
- {
- PyObject *tmp = r;
-
- if (!(r = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, tmp)))
- {
- Py_DECREF(tmp);
- return NULL;
- }
- }
-
return r;
}
--- 1135,1140 ----
***************
*** 1532,1546 ****
}
static PyObject *
! DictionaryPopItem(DictionaryObject *self, PyObject *args)
{
! PyObject *keyObject;
! if (!PyArg_ParseTuple(args, "O", &keyObject))
return NULL;
! return _DictionaryItem(self, keyObject,
! DICT_FLAG_POP|DICT_FLAG_RETURN_PAIR);
}
static PyObject *
--- 1521,1558 ----
}
static PyObject *
! DictionaryPopItem(DictionaryObject *self)
{
! hashitem_T *hi;
! PyObject *r;
! PyObject *valObject;
! dictitem_T *di;
! if (self->dict->dv_hashtab.ht_used == 0)
! {
! PyErr_SetNone(PyExc_KeyError);
! return NULL;
! }
!
! hi = self->dict->dv_hashtab.ht_array;
! while (HASHITEM_EMPTY(hi))
! ++hi;
!
! di = dict_lookup(hi);
!
! if (!(valObject = ConvertToPyObject(&di->di_tv)))
return NULL;
! if (!(r = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, valObject)))
! {
! Py_DECREF(valObject);
! return NULL;
! }
!
! hash_remove(&self->dict->dv_hashtab, hi);
! dictitem_free(di);
!
! return r;
}
static PyObject *
***************
*** 1580,1586 ****
{"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""},
{"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
{"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
! {"popitem", (PyCFunction)DictionaryPopItem, METH_VARARGS, ""},
{"has_key", (PyCFunction)DictionaryHasKey, METH_VARARGS, ""},
{"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
{ NULL, NULL, 0, NULL}
--- 1592,1598 ----
{"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""},
{"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
{"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
! {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""},
{"has_key", (PyCFunction)DictionaryHasKey, METH_VARARGS, ""},
{"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
{ NULL, NULL, 0, NULL}
diff -cr vim.7698aef18252/src/testdir/test86.in vim.aeb6697bc685/src/testdir/test86.in
*** vim.7698aef18252/src/testdir/test86.in 2013-06-02 07:00:35.499979930 +0400
--- vim.aeb6697bc685/src/testdir/test86.in 2013-06-02 07:00:35.546979598 +0400
***************
*** 83,89 ****
:$put =pyeval('repr(''1'' in d)')
:$put =pyeval('repr(list(iter(d)))')
:$put =string(d)
! :$put =pyeval('repr(d.popitem(''0''))')
:$put =pyeval('repr(d.get(''0''))')
:$put =pyeval('repr(list(iter(d)))')
:"
--- 83,89 ----
:$put =pyeval('repr(''1'' in d)')
:$put =pyeval('repr(list(iter(d)))')
:$put =string(d)
! :$put =pyeval('repr(d.popitem())')
:$put =pyeval('repr(d.get(''0''))')
:$put =pyeval('repr(list(iter(d)))')
:"
***************
*** 226,232 ****
em('d[u"a\\0b"]=1')
em('d.pop("abc")')
! em('d.popitem("abc")')
EOF
:$put =messages
:unlet messages
--- 226,232 ----
em('d[u"a\\0b"]=1')
em('d.pop("abc")')
! em('d.popitem()')
EOF
:$put =messages
:unlet messages
diff -cr vim.7698aef18252/src/testdir/test86.ok vim.aeb6697bc685/src/testdir/test86.ok
*** vim.7698aef18252/src/testdir/test86.ok 2013-06-02 07:00:35.500979923 +0400
--- vim.aeb6697bc685/src/testdir/test86.ok 2013-06-02 07:00:35.547979591 +0400
***************
*** 26,32 ****
False
['0']
{'0': -1}
! ('', -1L)
None
[]
[0, 1, 2, 3]
--- 26,32 ----
False
['0']
{'0': -1}
! ('0', -1L)
None
[]
[0, 1, 2, 3]
***************
*** 672,678 ****
d.update((("a", FailingMappingKey()),)):(<type 'exceptions.NotImplementedError'>, NotImplementedError())
<<< Finished
>> DictionaryPopItem
! d.popitem(1, 2):(<type 'exceptions.TypeError'>, TypeError('function takes exactly 1 argument (2 given)',))
>> DictionaryHasKey
d.has_key():(<type 'exceptions.TypeError'>, TypeError('function takes exactly 1 argument (0 given)',))
> List
--- 672,678 ----
d.update((("a", FailingMappingKey()),)):(<type 'exceptions.NotImplementedError'>, NotImplementedError())
<<< Finished
>> DictionaryPopItem
! d.popitem(1, 2):(<type 'exceptions.TypeError'>, TypeError('popitem() takes no arguments (2 given)',))
>> DictionaryHasKey
d.has_key():(<type 'exceptions.TypeError'>, TypeError('function takes exactly 1 argument (0 given)',))
> List
diff -cr vim.7698aef18252/src/testdir/test87.in vim.aeb6697bc685/src/testdir/test87.in
*** vim.7698aef18252/src/testdir/test87.in 2013-06-02 07:00:35.489980001 +0400
--- vim.aeb6697bc685/src/testdir/test87.in 2013-06-02 07:00:35.532979697 +0400
***************
*** 77,83 ****
:$put =py3eval('repr(''1'' in d)')
:$put =py3eval('repr(list(iter(d)))')
:$put =string(d)
! :$put =py3eval('repr(d.popitem(''0''))')
:$put =py3eval('repr(d.get(''0''))')
:$put =py3eval('repr(list(iter(d)))')
:"
--- 77,83 ----
:$put =py3eval('repr(''1'' in d)')
:$put =py3eval('repr(list(iter(d)))')
:$put =string(d)
! :$put =py3eval('repr(d.popitem())')
:$put =py3eval('repr(d.get(''0''))')
:$put =py3eval('repr(list(iter(d)))')
:"
***************
*** 220,226 ****
em('d[b"a\\0b"]=1')
em('d.pop("abc")')
! em('d.popitem("abc")')
EOF
:$put =messages
:unlet messages
--- 220,226 ----
em('d[b"a\\0b"]=1')
em('d.pop("abc")')
! em('d.popitem()')
EOF
:$put =messages
:unlet messages
diff -cr vim.7698aef18252/src/testdir/test87.ok vim.aeb6697bc685/src/testdir/test87.ok
*** vim.7698aef18252/src/testdir/test87.ok 2013-06-02 07:00:35.491979987 +0400
--- vim.aeb6697bc685/src/testdir/test87.ok 2013-06-02 07:00:35.536979669 +0400
***************
*** 26,32 ****
False
[b'0']
{'0': -1}
! (b'', -1)
None
[]
[0, 1, 2, 3]
--- 26,32 ----
False
[b'0']
{'0': -1}
! (b'0', -1)
None
[]
[0, 1, 2, 3]
***************
*** 669,675 ****
d.update((("a", FailingMappingKey()),)):(<class 'NotImplementedError'>, NotImplementedError())
<<< Finished
>> DictionaryPopItem
! d.popitem(1, 2):(<class 'TypeError'>, TypeError('function takes exactly 1 argument (2 given)',))
>> DictionaryHasKey
d.has_key():(<class 'TypeError'>, TypeError('function takes exactly 1 argument (0 given)',))
> List
--- 669,675 ----
d.update((("a", FailingMappingKey()),)):(<class 'NotImplementedError'>, NotImplementedError())
<<< Finished
>> DictionaryPopItem
! d.popitem(1, 2):(<class 'TypeError'>, TypeError('popitem() takes no arguments (2 given)',))
>> DictionaryHasKey
d.has_key():(<class 'TypeError'>, TypeError('function takes exactly 1 argument (0 given)',))
> List