# HG changeset patch
# User ZyX <[email protected]>
# Date 1382213960 -14400
#      Sun Oct 20 00:19:20 2013 +0400
# Branch fix-python-empty-update
# Node ID 9c70b108fc842e6aabfe579ebd08be68d5a73e75
# Parent  92c9748e0ccbc42a5e28ce8fb9b8818e756a06da
Make vim.Dictionary.update() without arguments do nothing

Python own dict.update() does not throw any errors when called without arguments
hence vim.Dictionary.update() should not also do this.

diff -r 92c9748e0ccb -r 9c70b108fc84 src/if_py_both.h
--- a/src/if_py_both.h  Sun Oct 06 17:46:56 2013 +0200
+++ b/src/if_py_both.h  Sun Oct 20 00:19:20 2013 +0400
@@ -1885,11 +1885,17 @@
     }
     else
     {
-       PyObject        *obj;
-
-       if (!PyArg_ParseTuple(args, "O", &obj))
+       PyObject        *obj = NULL;
+
+       if (!PyArg_ParseTuple(args, "|O", &obj))
            return NULL;
 
+       if (obj == NULL)
+       {
+           Py_INCREF(Py_None);
+           return Py_None;
+       }
+
        if (PyObject_HasAttrString(obj, "keys"))
            return DictionaryUpdate(self, NULL, obj);
        else
diff -r 92c9748e0ccb -r 9c70b108fc84 src/testdir/test86.in
--- a/src/testdir/test86.in     Sun Oct 06 17:46:56 2013 +0200
+++ b/src/testdir/test86.in     Sun Oct 20 00:19:20 2013 +0400
@@ -39,6 +39,7 @@
 py << EOF
 d=vim.bindeval('d')
 d['1']='asd'
+d.update()  # Must not do anything, including throwing errors
 d.update(b=[1, 2, f])
 d.update((('-1', {'a': 1}),))
 d.update({'0': -1})
diff -r 92c9748e0ccb -r 9c70b108fc84 src/testdir/test87.in
--- a/src/testdir/test87.in     Sun Oct 06 17:46:56 2013 +0200
+++ b/src/testdir/test87.in     Sun Oct 20 00:19:20 2013 +0400
@@ -33,6 +33,7 @@
 py3 << EOF
 d=vim.bindeval('d')
 d['1']='asd'
+d.update()  # Must not do anything, including throwing errors
 d.update(b=[1, 2, f])
 d.update((('-1', {'a': 1}),))
 d.update({'0': -1})

-- 
-- 
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 -crN vim-small-patches.92c9748e0ccb/src/if_py_both.h vim-small-patches.9c70b108fc84/src/if_py_both.h
*** vim-small-patches.92c9748e0ccb/src/if_py_both.h	2013-10-20 01:27:31.158203822 +0400
--- vim-small-patches.9c70b108fc84/src/if_py_both.h	2013-10-20 01:27:31.164203761 +0400
***************
*** 1885,1895 ****
      }
      else
      {
! 	PyObject	*obj;
  
! 	if (!PyArg_ParseTuple(args, "O", &obj))
  	    return NULL;
  
  	if (PyObject_HasAttrString(obj, "keys"))
  	    return DictionaryUpdate(self, NULL, obj);
  	else
--- 1885,1901 ----
      }
      else
      {
! 	PyObject	*obj = NULL;
  
! 	if (!PyArg_ParseTuple(args, "|O", &obj))
  	    return NULL;
  
+ 	if (obj == NULL)
+ 	{
+ 	    Py_INCREF(Py_None);
+ 	    return Py_None;
+ 	}
+ 
  	if (PyObject_HasAttrString(obj, "keys"))
  	    return DictionaryUpdate(self, NULL, obj);
  	else
diff -crN vim-small-patches.92c9748e0ccb/src/testdir/test86.in vim-small-patches.9c70b108fc84/src/testdir/test86.in
*** vim-small-patches.92c9748e0ccb/src/testdir/test86.in	2013-10-20 01:27:31.160203802 +0400
--- vim-small-patches.9c70b108fc84/src/testdir/test86.in	2013-10-20 01:27:31.166203740 +0400
***************
*** 39,44 ****
--- 39,45 ----
  py << EOF
  d=vim.bindeval('d')
  d['1']='asd'
+ d.update()  # Must not do anything, including throwing errors
  d.update(b=[1, 2, f])
  d.update((('-1', {'a': 1}),))
  d.update({'0': -1})
diff -crN vim-small-patches.92c9748e0ccb/src/testdir/test87.in vim-small-patches.9c70b108fc84/src/testdir/test87.in
*** vim-small-patches.92c9748e0ccb/src/testdir/test87.in	2013-10-20 01:27:31.156203842 +0400
--- vim-small-patches.9c70b108fc84/src/testdir/test87.in	2013-10-20 01:27:31.162203781 +0400
***************
*** 33,38 ****
--- 33,39 ----
  py3 << EOF
  d=vim.bindeval('d')
  d['1']='asd'
+ d.update()  # Must not do anything, including throwing errors
  d.update(b=[1, 2, f])
  d.update((('-1', {'a': 1}),))
  d.update({'0': -1})

Raspunde prin e-mail lui