Skip to content

Commit

Permalink
patch 7.4.1731
Browse files Browse the repository at this point in the history
Problem:    Python: turns partial into simple funcref.
Solution:   Use partials like partials. (Nikolai Pavlov, closes vim#734)
  • Loading branch information
brammool committed Apr 14, 2016
1 parent 58de0e2 commit 8110a09
Show file tree
Hide file tree
Showing 11 changed files with 923 additions and 62 deletions.
28 changes: 24 additions & 4 deletions runtime/doc/if_pyth.txt
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,25 @@ vim.List object *python-List*
class List(vim.List): # Subclassing
vim.Function object *python-Function*
Function-like object, acting like vim |Funcref| object. Supports `.name`
attribute and is callable. Accepts special keyword argument `self`, see
|Dictionary-function|. You can also use `vim.Function(name)` constructor,
it is the same as `vim.bindeval('function(%s)'%json.dumps(name))`.
Function-like object, acting like vim |Funcref| object. Accepts special
keyword argument `self`, see |Dictionary-function|. You can also use
`vim.Function(name)` constructor, it is the same as
`vim.bindeval('function(%s)'%json.dumps(name))`.

Attributes (read-only):
Attribute Description ~
name Function name.
args `None` or a |python-List| object with arguments. Note that
this is a copy of the arguments list, constructed each time
you request this attribute. Modifications made to the list
will be ignored (but not to the containers inside argument
list: this is like |copy()| and not |deepcopy()|).
self `None` or a |python-Dictionary| object with self
dictionary. Note that explicit `self` keyword used when
calling resulting object overrides this attribute.

Constructor additionally accepts `args` and `self` keywords. If any of
them is given then it constructs a partial, see |function()|.

Examples: >
f = vim.Function('tr') # Constructor
Expand All @@ -670,6 +685,11 @@ vim.Function object *python-Function*
print f(self={}) # Like call('DictFun', [], {})
print isinstance(f, vim.Function) # True
p = vim.Function('DictFun', self={})
print f()
p = vim.Function('tr', args=['abc', 'a'])
print f('b')
==============================================================================
8. pyeval() and py3eval() Vim functions *python-pyeval*

Expand Down
3 changes: 1 addition & 2 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ static long dict_len(dict_T *d);
static char_u *dict2string(typval_T *tv, int copyID);
static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate);
static char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
static char_u *tv2string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
static char_u *string_quote(char_u *str, int function);
static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate);
static int find_internal_func(char_u *name);
Expand Down Expand Up @@ -8153,7 +8152,7 @@ echo_string(
* Puts quotes around strings, so that they can be parsed back by eval().
* May return NULL.
*/
static char_u *
char_u *
tv2string(
typval_T *tv,
char_u **tofree,
Expand Down
Loading

0 comments on commit 8110a09

Please sign in to comment.