Skip to content

Commit de32309

Browse files
committed
patch 8.0.1280: Python None cannot be converted to a Vim type
Problem: Python None cannot be converted to a Vim type. Solution: Convert it to v:none. (Ken Takata)
1 parent 040c1fe commit de32309

5 files changed

Lines changed: 56 additions & 47 deletions

File tree

runtime/doc/if_pyth.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()|
715715
functions to evaluate Python expressions and pass their values to Vim script.
716716
|pyxeval()| is also available.
717717

718+
The Python value "None" is converted to v:none.
719+
718720
==============================================================================
719721
9. Dynamic loading *python-dynamic*
720722

src/if_py_both.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5713,7 +5713,7 @@ run_eval(const char *cmd, typval_T *rettv
57135713
}
57145714
else
57155715
{
5716-
if (run_ret != Py_None && ConvertFromPyObject(run_ret, rettv) == -1)
5716+
if (ConvertFromPyObject(run_ret, rettv) == -1)
57175717
EMSG(_("E859: Failed to convert returned python object to vim value"));
57185718
Py_DECREF(run_ret);
57195719
}
@@ -6231,6 +6231,11 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
62316231

62326232
Py_DECREF(num);
62336233
}
6234+
else if (obj == Py_None)
6235+
{
6236+
tv->v_type = VAR_SPECIAL;
6237+
tv->vval.v_number = VVAL_NONE;
6238+
}
62346239
else
62356240
{
62366241
PyErr_FORMAT(PyExc_TypeError,

src/testdir/test86.ok

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ll:[1]
8787
['a', 'b']
8888
['c', 1]
8989
['d', ['e']]
90-
pyeval("None") = 0
90+
pyeval("None") = v:none
9191
0.0
9292
"\0": Vim(let):E859:
9393
{"\0": 1}: Vim(let):E859:
@@ -768,7 +768,7 @@ d["a"] = {"abcF" : FailingIter()}:TypeError:('unable to convert FailingIter to v
768768
d["a"] = {"abcF" : FailingIterNext()}:NotImplementedError:('next',)
769769
<<< Finished
770770
>>> Testing ConvertFromPyObject using d["a"] = {"abcF" : %s}
771-
d["a"] = {"abcF" : None}:TypeError:('unable to convert NoneType to vim structure',)
771+
d["a"] = {"abcF" : None}:NOT FAILED
772772
d["a"] = {"abcF" : {"": 1}}:ValueError:('empty keys are not allowed',)
773773
d["a"] = {"abcF" : {u"": 1}}:ValueError:('empty keys are not allowed',)
774774
d["a"] = {"abcF" : FailingMapping()}:NotImplementedError:('keys',)
@@ -795,7 +795,7 @@ d["a"] = Mapping({"abcG" : FailingIter()}):TypeError:('unable to convert Failing
795795
d["a"] = Mapping({"abcG" : FailingIterNext()}):NotImplementedError:('next',)
796796
<<< Finished
797797
>>> Testing ConvertFromPyObject using d["a"] = Mapping({"abcG" : %s})
798-
d["a"] = Mapping({"abcG" : None}):TypeError:('unable to convert NoneType to vim structure',)
798+
d["a"] = Mapping({"abcG" : None}):NOT FAILED
799799
d["a"] = Mapping({"abcG" : {"": 1}}):ValueError:('empty keys are not allowed',)
800800
d["a"] = Mapping({"abcG" : {u"": 1}}):ValueError:('empty keys are not allowed',)
801801
d["a"] = Mapping({"abcG" : FailingMapping()}):NotImplementedError:('keys',)
@@ -807,7 +807,7 @@ d["a"] = FailingIter():TypeError:('unable to convert FailingIter to vim structur
807807
d["a"] = FailingIterNext():NotImplementedError:('next',)
808808
<<< Finished
809809
>>> Testing ConvertFromPyObject using d["a"] = %s
810-
d["a"] = None:TypeError:('unable to convert NoneType to vim structure',)
810+
d["a"] = None:NOT FAILED
811811
d["a"] = {"": 1}:ValueError:('empty keys are not allowed',)
812812
d["a"] = {u"": 1}:ValueError:('empty keys are not allowed',)
813813
d["a"] = FailingMapping():NotImplementedError:('keys',)
@@ -844,7 +844,7 @@ d.update({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to
844844
d.update({"abcF" : FailingIterNext()}):NotImplementedError:('next',)
845845
<<< Finished
846846
>>> Testing ConvertFromPyObject using d.update({"abcF" : %s})
847-
d.update({"abcF" : None}):TypeError:('unable to convert NoneType to vim structure',)
847+
d.update({"abcF" : None}):NOT FAILED
848848
d.update({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',)
849849
d.update({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',)
850850
d.update({"abcF" : FailingMapping()}):NotImplementedError:('keys',)
@@ -871,7 +871,7 @@ d.update(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert Failin
871871
d.update(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',)
872872
<<< Finished
873873
>>> Testing ConvertFromPyObject using d.update(Mapping({"abcG" : %s}))
874-
d.update(Mapping({"abcG" : None})):TypeError:('unable to convert NoneType to vim structure',)
874+
d.update(Mapping({"abcG" : None})):NOT FAILED
875875
d.update(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',)
876876
d.update(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',)
877877
d.update(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',)
@@ -915,7 +915,7 @@ d.update((("a", {"abcF" : FailingIter()}),)):TypeError:('unable to convert Faili
915915
d.update((("a", {"abcF" : FailingIterNext()}),)):NotImplementedError:('next',)
916916
<<< Finished
917917
>>> Testing ConvertFromPyObject using d.update((("a", {"abcF" : %s}),))
918-
d.update((("a", {"abcF" : None}),)):TypeError:('unable to convert NoneType to vim structure',)
918+
d.update((("a", {"abcF" : None}),)):error:("failed to add key 'a' to dictionary",)
919919
d.update((("a", {"abcF" : {"": 1}}),)):ValueError:('empty keys are not allowed',)
920920
d.update((("a", {"abcF" : {u"": 1}}),)):ValueError:('empty keys are not allowed',)
921921
d.update((("a", {"abcF" : FailingMapping()}),)):NotImplementedError:('keys',)
@@ -942,7 +942,7 @@ d.update((("a", Mapping({"abcG" : FailingIter()})),)):TypeError:('unable to conv
942942
d.update((("a", Mapping({"abcG" : FailingIterNext()})),)):NotImplementedError:('next',)
943943
<<< Finished
944944
>>> Testing ConvertFromPyObject using d.update((("a", Mapping({"abcG" : %s})),))
945-
d.update((("a", Mapping({"abcG" : None})),)):TypeError:('unable to convert NoneType to vim structure',)
945+
d.update((("a", Mapping({"abcG" : None})),)):error:("failed to add key 'a' to dictionary",)
946946
d.update((("a", Mapping({"abcG" : {"": 1}})),)):ValueError:('empty keys are not allowed',)
947947
d.update((("a", Mapping({"abcG" : {u"": 1}})),)):ValueError:('empty keys are not allowed',)
948948
d.update((("a", Mapping({"abcG" : FailingMapping()})),)):NotImplementedError:('keys',)
@@ -954,7 +954,7 @@ d.update((("a", FailingIter()),)):TypeError:('unable to convert FailingIter to v
954954
d.update((("a", FailingIterNext()),)):NotImplementedError:('next',)
955955
<<< Finished
956956
>>> Testing ConvertFromPyObject using d.update((("a", %s),))
957-
d.update((("a", None),)):TypeError:('unable to convert NoneType to vim structure',)
957+
d.update((("a", None),)):error:("failed to add key 'a' to dictionary",)
958958
d.update((("a", {"": 1}),)):ValueError:('empty keys are not allowed',)
959959
d.update((("a", {u"": 1}),)):ValueError:('empty keys are not allowed',)
960960
d.update((("a", FailingMapping()),)):NotImplementedError:('keys',)
@@ -993,7 +993,7 @@ vim.List([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter t
993993
vim.List([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',)
994994
<<< Finished
995995
>>> Testing ConvertFromPyObject using vim.List([{"abcF" : %s}])
996-
vim.List([{"abcF" : None}]):TypeError:('unable to convert NoneType to vim structure',)
996+
vim.List([{"abcF" : None}]):NOT FAILED
997997
vim.List([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',)
998998
vim.List([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',)
999999
vim.List([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',)
@@ -1020,7 +1020,7 @@ vim.List([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert Fail
10201020
vim.List([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',)
10211021
<<< Finished
10221022
>>> Testing ConvertFromPyObject using vim.List([Mapping({"abcG" : %s})])
1023-
vim.List([Mapping({"abcG" : None})]):TypeError:('unable to convert NoneType to vim structure',)
1023+
vim.List([Mapping({"abcG" : None})]):NOT FAILED
10241024
vim.List([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',)
10251025
vim.List([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',)
10261026
vim.List([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',)
@@ -1032,7 +1032,7 @@ vim.List([FailingIter()]):TypeError:('unable to convert FailingIter to vim struc
10321032
vim.List([FailingIterNext()]):NotImplementedError:('next',)
10331033
<<< Finished
10341034
>>> Testing ConvertFromPyObject using vim.List([%s])
1035-
vim.List([None]):TypeError:('unable to convert NoneType to vim structure',)
1035+
vim.List([None]):NOT FAILED
10361036
vim.List([{"": 1}]):ValueError:('empty keys are not allowed',)
10371037
vim.List([{u"": 1}]):ValueError:('empty keys are not allowed',)
10381038
vim.List([FailingMapping()]):NotImplementedError:('keys',)
@@ -1078,7 +1078,7 @@ l[:] = [{"abcF" : FailingIter()}]:TypeError:('unable to convert FailingIter to v
10781078
l[:] = [{"abcF" : FailingIterNext()}]:NotImplementedError:('next',)
10791079
<<< Finished
10801080
>>> Testing ConvertFromPyObject using l[:] = [{"abcF" : %s}]
1081-
l[:] = [{"abcF" : None}]:TypeError:('unable to convert NoneType to vim structure',)
1081+
l[:] = [{"abcF" : None}]:NOT FAILED
10821082
l[:] = [{"abcF" : {"": 1}}]:ValueError:('empty keys are not allowed',)
10831083
l[:] = [{"abcF" : {u"": 1}}]:ValueError:('empty keys are not allowed',)
10841084
l[:] = [{"abcF" : FailingMapping()}]:NotImplementedError:('keys',)
@@ -1105,7 +1105,7 @@ l[:] = [Mapping({"abcG" : FailingIter()})]:TypeError:('unable to convert Failing
11051105
l[:] = [Mapping({"abcG" : FailingIterNext()})]:NotImplementedError:('next',)
11061106
<<< Finished
11071107
>>> Testing ConvertFromPyObject using l[:] = [Mapping({"abcG" : %s})]
1108-
l[:] = [Mapping({"abcG" : None})]:TypeError:('unable to convert NoneType to vim structure',)
1108+
l[:] = [Mapping({"abcG" : None})]:NOT FAILED
11091109
l[:] = [Mapping({"abcG" : {"": 1}})]:ValueError:('empty keys are not allowed',)
11101110
l[:] = [Mapping({"abcG" : {u"": 1}})]:ValueError:('empty keys are not allowed',)
11111111
l[:] = [Mapping({"abcG" : FailingMapping()})]:NotImplementedError:('keys',)
@@ -1117,7 +1117,7 @@ l[:] = [FailingIter()]:TypeError:('unable to convert FailingIter to vim structur
11171117
l[:] = [FailingIterNext()]:NotImplementedError:('next',)
11181118
<<< Finished
11191119
>>> Testing ConvertFromPyObject using l[:] = [%s]
1120-
l[:] = [None]:TypeError:('unable to convert NoneType to vim structure',)
1120+
l[:] = [None]:NOT FAILED
11211121
l[:] = [{"": 1}]:ValueError:('empty keys are not allowed',)
11221122
l[:] = [{u"": 1}]:ValueError:('empty keys are not allowed',)
11231123
l[:] = [FailingMapping()]:NotImplementedError:('keys',)
@@ -1149,7 +1149,7 @@ l.extend([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter t
11491149
l.extend([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',)
11501150
<<< Finished
11511151
>>> Testing ConvertFromPyObject using l.extend([{"abcF" : %s}])
1152-
l.extend([{"abcF" : None}]):TypeError:('unable to convert NoneType to vim structure',)
1152+
l.extend([{"abcF" : None}]):NOT FAILED
11531153
l.extend([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',)
11541154
l.extend([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',)
11551155
l.extend([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',)
@@ -1176,7 +1176,7 @@ l.extend([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert Fail
11761176
l.extend([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',)
11771177
<<< Finished
11781178
>>> Testing ConvertFromPyObject using l.extend([Mapping({"abcG" : %s})])
1179-
l.extend([Mapping({"abcG" : None})]):TypeError:('unable to convert NoneType to vim structure',)
1179+
l.extend([Mapping({"abcG" : None})]):NOT FAILED
11801180
l.extend([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',)
11811181
l.extend([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',)
11821182
l.extend([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',)
@@ -1188,7 +1188,7 @@ l.extend([FailingIter()]):TypeError:('unable to convert FailingIter to vim struc
11881188
l.extend([FailingIterNext()]):NotImplementedError:('next',)
11891189
<<< Finished
11901190
>>> Testing ConvertFromPyObject using l.extend([%s])
1191-
l.extend([None]):TypeError:('unable to convert NoneType to vim structure',)
1191+
l.extend([None]):NOT FAILED
11921192
l.extend([{"": 1}]):ValueError:('empty keys are not allowed',)
11931193
l.extend([{u"": 1}]):ValueError:('empty keys are not allowed',)
11941194
l.extend([FailingMapping()]):NotImplementedError:('keys',)
@@ -1236,7 +1236,7 @@ f({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to vim str
12361236
f({"abcF" : FailingIterNext()}):NotImplementedError:('next',)
12371237
<<< Finished
12381238
>>> Testing ConvertFromPyObject using f({"abcF" : %s})
1239-
f({"abcF" : None}):TypeError:('unable to convert NoneType to vim structure',)
1239+
f({"abcF" : None}):NOT FAILED
12401240
f({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',)
12411241
f({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',)
12421242
f({"abcF" : FailingMapping()}):NotImplementedError:('keys',)
@@ -1263,7 +1263,7 @@ f(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter t
12631263
f(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',)
12641264
<<< Finished
12651265
>>> Testing ConvertFromPyObject using f(Mapping({"abcG" : %s}))
1266-
f(Mapping({"abcG" : None})):TypeError:('unable to convert NoneType to vim structure',)
1266+
f(Mapping({"abcG" : None})):NOT FAILED
12671267
f(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',)
12681268
f(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',)
12691269
f(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',)
@@ -1275,7 +1275,7 @@ f(FailingIter()):TypeError:('unable to convert FailingIter to vim structure',)
12751275
f(FailingIterNext()):NotImplementedError:('next',)
12761276
<<< Finished
12771277
>>> Testing ConvertFromPyObject using f(%s)
1278-
f(None):TypeError:('unable to convert NoneType to vim structure',)
1278+
f(None):NOT FAILED
12791279
f({"": 1}):ValueError:('empty keys are not allowed',)
12801280
f({u"": 1}):ValueError:('empty keys are not allowed',)
12811281
f(FailingMapping()):NotImplementedError:('keys',)
@@ -1302,7 +1302,7 @@ fd(self={"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to v
13021302
fd(self={"abcF" : FailingIterNext()}):NotImplementedError:('next',)
13031303
<<< Finished
13041304
>>> Testing ConvertFromPyObject using fd(self={"abcF" : %s})
1305-
fd(self={"abcF" : None}):TypeError:('unable to convert NoneType to vim structure',)
1305+
fd(self={"abcF" : None}):NOT FAILED
13061306
fd(self={"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',)
13071307
fd(self={"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',)
13081308
fd(self={"abcF" : FailingMapping()}):NotImplementedError:('keys',)
@@ -1329,7 +1329,7 @@ fd(self=Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert Failing
13291329
fd(self=Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',)
13301330
<<< Finished
13311331
>>> Testing ConvertFromPyObject using fd(self=Mapping({"abcG" : %s}))
1332-
fd(self=Mapping({"abcG" : None})):TypeError:('unable to convert NoneType to vim structure',)
1332+
fd(self=Mapping({"abcG" : None})):NOT FAILED
13331333
fd(self=Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',)
13341334
fd(self=Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',)
13351335
fd(self=Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',)

0 commit comments

Comments
 (0)