nutti / fake-bpy-module

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

Issue with ID return type on ID class and Depsgraph #270

Open Andrej730 opened 1 week ago

Andrej730 commented 1 week ago

See example below, since those methods on ID and Depsgraph are defined with -> ID, it always returns ID and doesn't consider the actual type.

image

To resolve this for ID methods using -> typing.Self would work. For Depsgraph it would require a typing.TypeVar bounded to ID in both Depsgraph.id_eval_get argument and return types.

import bpy
from typing import assert_type

material = bpy.data.materials["test"]
# "assert_type" mismatch: expected "Material" but received "ID"
assert_type(material.copy(), bpy.types.Material)

obj = bpy.data.objects["Test"]
depsgraph = bpy.context.evaluated_depsgraph_get()

# "assert_type" mismatch: expected "Object" but received "ID"
assert_type(obj.override_create(), bpy.types.Object)
assert_type(obj.override_hierarchy_create(), bpy.types.Object)
assert_type(obj.make_local(), bpy.types.Object)
assert_type(obj.evaluated_get(depsgraph), bpy.types.Object)
assert_type(depsgraph.id_eval_get(obj), bpy.types.Object)
Road-hog123 commented 6 days ago

Duplicate of #161.