mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
- tools/returns.py reads what a function written in Python returns from its source, where its docstring has no :rtype: (or a Python property's getter, no :type:): the type every `return` gives when each shows one (a literal, a comparison, a builtin's result, a str method on a string, os.path's, a local only ever bound to such), "T | None" when a path falls off the end; anything else leaves it any. dump.py gives it as `ret`, gen uses it for functions and Python properties alike: CyclesPreferences.has_active_device() boolean, Mesh.edge_keys an array, BoneCollection.bones_recursive a set (33 members). - pymod.ts types the items of sequences whose name doesn't give them, from the C (bmesh_py_types*.cc, idprop_py_api.cc): bm.select_history[i] a vertex, edge or face; a BMElemSeq's any element; a layer collection's BMLayerItems; a deform vertex's [group] a weight; an IDPropertyArray's numbers or booleans. BMVert/BMEdge/BMFace/ BMLoop[layer] and an ID property group (keyed by name) no longer claim a number index. - dump.py leaves out Python's own names a Blender module imports (anim_utils' Mapping, Sequence, Iterable, typing aliases, dataclass), and keeps a private class the module's functions name as their :rtype: (bpy.props' _PropertyDeferred, so FloatProperty() and the rest return it). - cret.ts reads `(PyCFunction)(void *)(name)` entries (GPUShaderCreateInfo's depth_write, fragment_out, push_constant, uniform_buf: None) and a returned local by its every assignment (libraries.write None, bpy.utils.units.to_value float, bpy.app.help_text str): cret.json 284 method and 123 property names. - Declarations typed any: bpy.types 51 -> 32 of 16 684; modules outside RNA 104 -> 47 of 1 440. Proven: tools/gen.sh from Blender 5.2.1 (tools/cret.sh 5.2.1 first); sdk/blender's tsc and its 16 bun tests pass, with test/returns.test.ts: the reader's 18 cases, and every member it types on live meshes, bone collections and Cycles' preferences reads as that type in Blender.
// README.md's example, type-checked with the tests (tsc -p .)
import { bpy, py, type Ptr, type types } from "raea/blender";
export default async function () {
bpy.ops.wm.read_factory_settings({ use_empty: true });
bpy.ops.mesh.primitive_monkey_add({ size: 2 });
const ob = py.pin(bpy.context.active_object!);
ob.modifiers.new("Smooth", "SUBSURF").levels = 2; // a SubsurfModifier, as Python gives
const m = bpy.data.materials.new("clay");
const bsdf = m.node_tree!.nodes.new("ShaderNodeBsdfPrincipled");
bsdf.inputs.$["Base Color"].default_value = [0.9, 0.35, 0.04, 1];
(ob.data as Ptr<types.Mesh>).materials.append(m);
ob.keyframe_insert({ data_path: "location", frame: 1 });
console.log(`${await ob.name} has ${await py.len((ob.data as Ptr<types.Mesh>).vertices)} vertices`);
}