Use @property/@setter for writable mathutils properties

Writable mathutils properties (Vector, Euler, etc.) were typed as plain
attributes with a union type, causing the getter to also return the union.
This made `obj.location.x` fail type checking since Sequence[float] has
no `.x`. Now these properties use @property for the getter (returning the
concrete mathutils type) and @setter accepting the wider union.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 15:54:40 +02:00
co-authored by Claude Opus 4.6
parent ace18808ca
commit e4284ce7d9
3 changed files with 79 additions and 22 deletions
+17 -13
View File
@@ -194,7 +194,11 @@ class VariableData(TypedDict):
value: str
class PropertyData(TypedDict):
class _PropertyDataOptional(TypedDict, total=False):
setter_type: str
class PropertyData(_PropertyDataOptional):
name: str
type: str
is_readonly: bool
@@ -1552,14 +1556,15 @@ def _property_data_from_member(
else:
is_readonly = not _is_getset_writable(cls, name)
prop_type = rtype or "object"
if not is_readonly and prop_type in _MATHUTILS_ARRAY_TYPES:
prop_type = f"{prop_type} | Sequence[float]"
return {
result: PropertyData = {
"name": name,
"type": prop_type,
"is_readonly": is_readonly,
"description": doc,
}
if not is_readonly and prop_type in _MATHUTILS_ARRAY_TYPES:
result["setter_type"] = f"{prop_type} | Sequence[float]"
return result
def _introspect_declared_class_members(
@@ -2661,17 +2666,16 @@ def _rna_struct_to_data(
for prop in getattr(struct_info, "properties", []):
prop_type = rna_property_to_type(prop)
is_readonly = bool(getattr(prop, "is_readonly", False))
prop_data: PropertyData = {
"name": str(getattr(prop, "identifier", "")),
"type": prop_type,
"is_readonly": is_readonly,
"description": str(getattr(prop, "description", "") or ""),
}
# Writable mathutils properties also accept Sequence[float] for assignment
if not is_readonly and prop_type in _MATHUTILS_ARRAY_TYPES:
prop_type = f"{prop_type} | Sequence[float]"
properties.append(
{
"name": str(getattr(prop, "identifier", "")),
"type": prop_type,
"is_readonly": is_readonly,
"description": str(getattr(prop, "description", "") or ""),
}
)
prop_data["setter_type"] = f"{prop_type} | Sequence[float]"
properties.append(prop_data)
methods: list[FunctionData] = []
is_collection_wrapper = sid in collection_element_types