fake-bpy-module icon indicating copy to clipboard operation
fake-bpy-module copied to clipboard

Issue with ID return type on ID class and Depsgraph

Open Andrej730 opened this issue 1 year ago • 1 comments

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)

Andrej730 avatar Jun 24 '24 13:06 Andrej730