A series of patches with python interface improvements:
- a change to make things more pythonic (this one)
- a bug fix (second patch)
- some refactoring (third and fourth)
- new interfaces (fifth and later)
# HG changeset patch
# User ZyX <[email protected]>
# Date 1366475031 -14400
# Branch python-extended-2
# Node ID ef93c86c326eaf3ff86a6f1a5a85a0efac52621f
# Parent ef341d8811b2af10623f034370600cc611b165d9
Make DictionaryItem raise KeyError in place of IndexError
diff -r ef341d8811b2 -r ef93c86c326e src/if_py_both.h
--- a/src/if_py_both.h Mon Apr 15 22:22:58 2013 +0200
+++ b/src/if_py_both.h Sat Apr 20 20:23:51 2013 +0400
@@ -861,7 +861,7 @@
if (di == NULL)
{
- PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
+ PyErr_SetString(PyExc_KeyError, _("no such key in dictionary"));
return NULL;
}
diff -r ef341d8811b2 -r ef93c86c326e src/if_python.c
--- a/src/if_python.c Mon Apr 15 22:22:58 2013 +0200
+++ b/src/if_python.c Sat Apr 20 20:23:51 2013 +0400
@@ -348,12 +348,14 @@
/* Imported exception objects */
static PyObject *imp_PyExc_AttributeError;
static PyObject *imp_PyExc_IndexError;
+static PyObject *imp_PyExc_KeyError;
static PyObject *imp_PyExc_KeyboardInterrupt;
static PyObject *imp_PyExc_TypeError;
static PyObject *imp_PyExc_ValueError;
# define PyExc_AttributeError imp_PyExc_AttributeError
# define PyExc_IndexError imp_PyExc_IndexError
+# define PyExc_KeyError imp_PyExc_KeyError
# define PyExc_KeyboardInterrupt imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError imp_PyExc_TypeError
# define PyExc_ValueError imp_PyExc_ValueError
@@ -579,11 +581,13 @@
PyObject *exdict = PyModule_GetDict(exmod);
imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError");
imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError");
+ imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError");
imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict,
"KeyboardInterrupt");
imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
Py_XINCREF(imp_PyExc_AttributeError);
Py_XINCREF(imp_PyExc_IndexError);
+ Py_XINCREF(imp_PyExc_KeyError);
Py_XINCREF(imp_PyExc_KeyboardInterrupt);
Py_XINCREF(imp_PyExc_TypeError);
Py_XINCREF(imp_PyExc_ValueError);
diff -r ef341d8811b2 -r ef93c86c326e src/if_python3.c
--- a/src/if_python3.c Mon Apr 15 22:22:58 2013 +0200
+++ b/src/if_python3.c Sat Apr 20 20:23:51 2013 +0400
@@ -327,12 +327,14 @@
/* Imported exception objects */
static PyObject *p3imp_PyExc_AttributeError;
static PyObject *p3imp_PyExc_IndexError;
+static PyObject *p3imp_PyExc_KeyError;
static PyObject *p3imp_PyExc_KeyboardInterrupt;
static PyObject *p3imp_PyExc_TypeError;
static PyObject *p3imp_PyExc_ValueError;
# define PyExc_AttributeError p3imp_PyExc_AttributeError
# define PyExc_IndexError p3imp_PyExc_IndexError
+# define PyExc_KeyError p3imp_PyExc_KeyError
# define PyExc_KeyboardInterrupt p3imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError p3imp_PyExc_TypeError
# define PyExc_ValueError p3imp_PyExc_ValueError
@@ -567,11 +569,13 @@
PyObject *exdict = PyModule_GetDict(exmod);
p3imp_PyExc_AttributeError = PyDict_GetItemString(exdict,
"AttributeError");
p3imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError");
+ p3imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError");
p3imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict,
"KeyboardInterrupt");
p3imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
p3imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
Py_XINCREF(p3imp_PyExc_AttributeError);
Py_XINCREF(p3imp_PyExc_IndexError);
+ Py_XINCREF(p3imp_PyExc_KeyError);
Py_XINCREF(p3imp_PyExc_KeyboardInterrupt);
Py_XINCREF(p3imp_PyExc_TypeError);
Py_XINCREF(p3imp_PyExc_ValueError);
diff -r ef341d8811b2 -r ef93c86c326e src/testdir/test86.ok
--- a/src/testdir/test86.ok Mon Apr 15 22:22:58 2013 +0200
+++ b/src/testdir/test86.ok Sat Apr 20 20:23:51 2013 +0400
@@ -38,7 +38,7 @@
Vim(python):E725:
Vim(python):E117:
[0.0, 0.0]
-IndexError
+KeyError
TypeError
TypeError
ValueError
diff -r ef341d8811b2 -r ef93c86c326e src/testdir/test87.ok
--- a/src/testdir/test87.ok Mon Apr 15 22:22:58 2013 +0200
+++ b/src/testdir/test87.ok Sat Apr 20 20:23:51 2013 +0400
@@ -38,7 +38,7 @@
Vim(py3):E725:
Vim(py3):E117:
[0.0, 0.0]
-IndexError
+KeyError
TypeError
TypeError
ValueError
--
--
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.ef341d8811b2/src/if_py_both.h vim.ef93c86c326e/src/if_py_both.h
*** vim.ef341d8811b2/src/if_py_both.h 2013-04-23 21:26:11.904349376 +0400
--- vim.ef93c86c326e/src/if_py_both.h 2013-04-23 21:26:11.913349112 +0400
***************
*** 861,867 ****
if (di == NULL)
{
! PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
return NULL;
}
--- 861,867 ----
if (di == NULL)
{
! PyErr_SetString(PyExc_KeyError, _("no such key in dictionary"));
return NULL;
}
diff -cr vim.ef341d8811b2/src/if_python3.c vim.ef93c86c326e/src/if_python3.c
*** vim.ef341d8811b2/src/if_python3.c 2013-04-23 21:26:11.902349435 +0400
--- vim.ef93c86c326e/src/if_python3.c 2013-04-23 21:26:11.911349170 +0400
***************
*** 327,338 ****
--- 327,340 ----
/* Imported exception objects */
static PyObject *p3imp_PyExc_AttributeError;
static PyObject *p3imp_PyExc_IndexError;
+ static PyObject *p3imp_PyExc_KeyError;
static PyObject *p3imp_PyExc_KeyboardInterrupt;
static PyObject *p3imp_PyExc_TypeError;
static PyObject *p3imp_PyExc_ValueError;
# define PyExc_AttributeError p3imp_PyExc_AttributeError
# define PyExc_IndexError p3imp_PyExc_IndexError
+ # define PyExc_KeyError p3imp_PyExc_KeyError
# define PyExc_KeyboardInterrupt p3imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError p3imp_PyExc_TypeError
# define PyExc_ValueError p3imp_PyExc_ValueError
***************
*** 567,577 ****
--- 569,581 ----
PyObject *exdict = PyModule_GetDict(exmod);
p3imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError");
p3imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError");
+ p3imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError");
p3imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
p3imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
p3imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
Py_XINCREF(p3imp_PyExc_AttributeError);
Py_XINCREF(p3imp_PyExc_IndexError);
+ Py_XINCREF(p3imp_PyExc_KeyError);
Py_XINCREF(p3imp_PyExc_KeyboardInterrupt);
Py_XINCREF(p3imp_PyExc_TypeError);
Py_XINCREF(p3imp_PyExc_ValueError);
diff -cr vim.ef341d8811b2/src/if_python.c vim.ef93c86c326e/src/if_python.c
*** vim.ef341d8811b2/src/if_python.c 2013-04-23 21:26:11.906349318 +0400
--- vim.ef93c86c326e/src/if_python.c 2013-04-23 21:26:11.915349053 +0400
***************
*** 348,359 ****
--- 348,361 ----
/* Imported exception objects */
static PyObject *imp_PyExc_AttributeError;
static PyObject *imp_PyExc_IndexError;
+ static PyObject *imp_PyExc_KeyError;
static PyObject *imp_PyExc_KeyboardInterrupt;
static PyObject *imp_PyExc_TypeError;
static PyObject *imp_PyExc_ValueError;
# define PyExc_AttributeError imp_PyExc_AttributeError
# define PyExc_IndexError imp_PyExc_IndexError
+ # define PyExc_KeyError imp_PyExc_KeyError
# define PyExc_KeyboardInterrupt imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError imp_PyExc_TypeError
# define PyExc_ValueError imp_PyExc_ValueError
***************
*** 579,589 ****
--- 581,593 ----
PyObject *exdict = PyModule_GetDict(exmod);
imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError");
imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError");
+ imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError");
imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
Py_XINCREF(imp_PyExc_AttributeError);
Py_XINCREF(imp_PyExc_IndexError);
+ Py_XINCREF(imp_PyExc_KeyError);
Py_XINCREF(imp_PyExc_KeyboardInterrupt);
Py_XINCREF(imp_PyExc_TypeError);
Py_XINCREF(imp_PyExc_ValueError);
diff -cr vim.ef341d8811b2/src/testdir/test86.ok vim.ef93c86c326e/src/testdir/test86.ok
*** vim.ef341d8811b2/src/testdir/test86.ok 2013-04-23 21:26:11.900349494 +0400
--- vim.ef93c86c326e/src/testdir/test86.ok 2013-04-23 21:26:11.909349229 +0400
***************
*** 38,44 ****
Vim(python):E725:
Vim(python):E117:
[0.0, 0.0]
! IndexError
TypeError
TypeError
ValueError
--- 38,44 ----
Vim(python):E725:
Vim(python):E117:
[0.0, 0.0]
! KeyError
TypeError
TypeError
ValueError
diff -cr vim.ef341d8811b2/src/testdir/test87.ok vim.ef93c86c326e/src/testdir/test87.ok
*** vim.ef341d8811b2/src/testdir/test87.ok 2013-04-23 21:26:11.900349494 +0400
--- vim.ef93c86c326e/src/testdir/test87.ok 2013-04-23 21:26:11.909349229 +0400
***************
*** 38,44 ****
Vim(py3):E725:
Vim(py3):E117:
[0.0, 0.0]
! IndexError
TypeError
TypeError
ValueError
--- 38,44 ----
Vim(py3):E725:
Vim(py3):E117:
[0.0, 0.0]
! KeyError
TypeError
TypeError
ValueError