Skip to content

Commit

Permalink
Update QuatDescriptor for typed-descriptor-lazy-default
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Jan 6, 2024
1 parent 0f99343 commit 1026009
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Quaternion/Quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,12 @@ class QuatDescriptor(TypedDescriptor):
----------
default : QuatLike, optional
Default value for the attribute. If not specified, the default for the
attribute is ``None``.
attribute is ``None``. If the intent is to default to a particular attitude,
this must be a tuple such as ``(0, 0, 0, 1)`` or ``(0, 0, 0)`` or a ``Quat``
object. A list is not allowed.
required : bool, optional
If ``True``, the attribute is required to be set explicitly when the object
is created. If ``False`` the default value is used if the attribute is not set.
If ``True``, the attribute is required to be set explicitly when the object is
created. If ``False`` the default value is used if the attribute is not set.
Examples
--------
Expand All @@ -1105,7 +1107,7 @@ class QuatDescriptor(TypedDescriptor):
>>> @dataclass
... class MyClass:
... att1: Quat = QuatDescriptor(required=True)
... att2: Quat = QuatDescriptor(default=[10, 20, 30])
... att2: Quat = QuatDescriptor(default=(10, 20, 30))
... att3: Quat | None = QuatDescriptor()
...
>>> obj = MyClass(att1=[0, 0, 0, 1])
Expand Down
4 changes: 2 additions & 2 deletions Quaternion/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,15 @@ class MyClass:
assert np.allclose(obj.quat.equatorial, [10, 20, 30], rtol=0, atol=1e-10)

with pytest.raises(
ValueError, match="cannot set required attribute 'quat' to None"
ValueError, match="attribute 'quat' is required and cannot be set to None"
):
MyClass()


def test_quat_descriptor_has_default():
@dataclass
class MyClass:
quat: Quat = QuatDescriptor(default=[10, 20, 30])
quat: Quat = QuatDescriptor(default=(10, 20, 30))

obj = MyClass()
assert np.allclose(obj.quat.equatorial, [10, 20, 30], rtol=0, atol=1e-10)
Expand Down

0 comments on commit 1026009

Please sign in to comment.