patch 9.1.0844: if_python: no way to pass local vars to python
Problem: if_python: no way to pass local vars to python
Solution: Add locals argument to py3eval(), pyeval() and pyxeval()
(Ben Jackson)
fixes: #8573
closes: #10594
Signed-off-by: Ben Jackson <puremourning@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt
index 6236841..0b6140f 100644
--- a/runtime/doc/if_pyth.txt
+++ b/runtime/doc/if_pyth.txt
@@ -1,4 +1,4 @@
-*if_pyth.txt* For Vim version 9.1. Last change: 2024 May 16
+*if_pyth.txt* For Vim version 9.1. Last change: 2024 Nov 06
VIM REFERENCE MANUAL by Paul Moore
@@ -201,6 +201,10 @@
[{'cmd': '/^eval_expr(arg, nextcmd)$/', 'static': 0, 'name': ~
'eval_expr', 'kind': 'f', 'filename': './src/eval.c'}] ~
+ NOTE: In vim9script, local variables in def functions are not visible
+ to to python evaluations. To pass local variables to python evaluations,
+ use the {locals} dict when calling |py3eval()| and friends.
+
vim.bindeval(str) *python-bindeval*
Like |python-eval|, but returns special objects described in
|python-bindeval-objects|. These python objects let you modify (|List|
@@ -741,6 +745,10 @@
functions to evaluate Python expressions and pass their values to Vim script.
|pyxeval()| is also available.
+You can inject local variables into the evaluation using the optional {locals}
+dict. This can be particularly useful in vim9script where vim.eval
+|python-eval| will not find locals in a def func.
+
The Python value "None" is converted to v:none.
==============================================================================