The lambda problem - how to send a constant value through it Is it possible to send a constant value to a (function-pointer-like) variable that makes use of lambda? Here is a very simplified version of what I want to do:

for p in range(property):
    property[p].update = lambda s, c: DoUpdate( s, c, p )


I would like the third arg p to be converted into a constant value. Or to send the value rather than the variable. Is this possible? To have p evaluated immediately?

I've seen answers that show to do it this way:

for p in range(property):
    property[p].update = lambda s, c, arg=p: DoUpdate( s, c, arg )


But I'm getting TypeError: update keyword: expected a function taking 2 arguments, not 3

Does this solution not work for Blender specifically? Or maybe I am doing it wrong? Does anyone know of a trick to convince lambda to record the value instead of the variable?
This works properly in Blender, since it uses a regular Python underneath. The following example uses a lambda with a default argument in order to evaluate the argument during declaration:

def test(a, b, c):
    print(f'a = {a}\nb = {b}\nc = {c}')

a = [1, 2, 3]
b = 2

x = lambda a, b, c=len(a): test(a, b, c)
a = [1, 2, 3, 4]
x(a, b)


The lambda uses a default argument for the third parameter, which is evaluated right away. The output is therefore:

a = [1, 2, 3, 4]
b = 2
c = 3


c still has the original length of a which was changed after declaring the lambda.



The issue that you're having is unrelated to the lambda though. The update callback is expected to take exactly two arguments. This is checked in the properties (bpy_props.c) through: 

if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
  return NULL;
}


If you can supply a function that takes two arguments it will work properly.