nutti / fake-bpy-module

Fake Blender Python API module collection for the code completion.
MIT License
1.37k stars 97 forks source link

VertexGroup.add index argument should accept Iterable[int] #148

Closed cmbasnett closed 11 months ago

cmbasnett commented 11 months ago

System Information

Expected behavior

When calling VertexGroup.add, I should be able to pass in an Iterable[int] (e.g., range, map etc.).

Description about the bug

The index argument only accepts bpy_prop_array[int] (I don't think this is even correct).

Screenshots/Files [Optional]

image

Additional comments [Optional]

nutti commented 11 months ago

@cmbasnett

We use bpy_prop_array to represent the Iterable. Ref: #125

BTW, all parameters not properties should be handled as typing.Iterable instead of bpy_prop_array? I'm afraid that fixed patch will make another side-effect.

nutti commented 11 months ago

@cmbasnett

Any response about above comment?

cmbasnett commented 11 months ago

I'm not sure if all of them should, as it depends on the internal implementation of the function in the C code.

In the code for VertexGroup.add, index (a bad name to begin with), it has the following for the argument:

  /* TODO: see how array size of 0 works, this shouldn't be used. */
  parm = RNA_def_int_array(func, "index", 1, nullptr, 0, 0, "", "List of indices", 0, 0);
  RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);

I suppose it is automatically converting the iterator to a List, since the RNA functions take the indices like this:

static void rna_VertexGroup_vertex_add(ID *id,
                                       bDeformGroup *def,
                                       ReportList *reports,
                                       const int *index,
                                       int index_num,
                                       float weight,
                                       int assignmode)

I think it would be a pretty safe assumption that iterators could be used for this one and other arguments that take a list of integers.

nutti commented 11 months ago

This issue is now fixed.