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

`Vector` - cannot convert to tuple / list / use slices

Open Andrej730 opened this issue 1 year ago • 1 comments
trafficstars

See example below - typing errors converting Vector to tuple/list/use slices though it is actually possible.

from mathutils import Vector
from typing import assert_type


v = Vector()
# Argument of type "Vector" cannot be assigned to parameter "iterable" of type "Iterable[_T_co@tuple]" in function "__new__"
#   "Vector" is incompatible with protocol "Iterable[_T_co@tuple]"
#     "__iter__" is not present
l = list(v)
assert_type(list(v), list[float])
t = tuple(v)
assert_type(t, tuple[float, ...])

# Argument of type "slice" cannot be assigned to parameter "key" of type "int" in function "__getitem__"
#   "slice" is incompatible with "int"
sl = v[:3]
assert_type(sl, tuple[float, ...])

sl2 = v[:2]
# Ideally this also should work since Vector size is always >= 2
# but not sure if it's possible.
assert_type(sl2, tuple[float, float])

Andrej730 avatar Jun 25 '24 12:06 Andrej730