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
+35
View File
@@ -420,6 +420,41 @@ class TestGeneratePropertyStub(unittest.TestCase):
self.assertIn("def type(self) -> str:", result)
self.assertIn("...", result)
def test_setter_type_generates_property_with_setter(self) -> None:
prop: PropertyData = {
"name": "location",
"type": "mathutils.Vector",
"is_readonly": False,
"description": "Object location.",
"setter_type": "mathutils.Vector | Sequence[float]",
}
result = generate_property_stub(prop)
self.assertIn("@property", result)
self.assertIn("def location(self) -> mathutils.Vector:", result)
self.assertIn('"""Object location."""', result)
self.assertIn("@location.setter", result)
self.assertIn(
"def location(self, value: mathutils.Vector | Sequence[float]) -> None: ...",
result,
)
def test_setter_type_no_description(self) -> None:
prop: PropertyData = {
"name": "rotation",
"type": "mathutils.Euler",
"is_readonly": False,
"description": "",
"setter_type": "mathutils.Euler | Sequence[float]",
}
result = generate_property_stub(prop)
self.assertIn("@property", result)
self.assertIn("def rotation(self) -> mathutils.Euler:", result)
self.assertIn("@rotation.setter", result)
self.assertIn(
"def rotation(self, value: mathutils.Euler | Sequence[float]) -> None: ...",
result,
)
class TestGenerateMethodStub(unittest.TestCase):
def test_simple_method(self) -> None: