nutti / fake-bpy-module

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

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

Closed Andrej730 closed 4 months ago

Andrej730 commented 5 months 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 5 months ago

Duplicate of #161.

nutti commented 4 months ago

This issue is now resolved.