nutti / fake-bpy-module

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

Object.data should be Mesh #131

Closed Pyrolistical closed 1 year ago

Pyrolistical commented 1 year ago

System Information

Expected behavior

bpy.types.Object.data should be of type bpy.types.Mesh

From Blender console:

>>> type(bpy.data.objects['some object'])
<class 'bpy_types.Object'>

>>> type(bpy.data.objects['some object'].data)
<class 'bpy_types.Mesh'>

Description about the bug

in fake-bpy-modules/bpy/types.py class Object defines data as:

data: 'ID' = None

Additional comments

I believe it should be Mesh as the workaround is to cast data

from typing import cast

mesh = cast(Mesh, some_object.data)
bpy.data.meshes.remove(mesh, do_unlink=True)
nutti commented 1 year ago

bpy.types.Object.data depends on the type of object (i.e. bpy.types.Camera for Camera object). We could not assume the specific type, and cast is needed for this case.