Skip to content

Commit c464daa

Browse files
committed
Expand docstring of has_compatible_units() validator
1 parent f7faa0a commit c464daa

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/pinttr/validators.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@ def has_compatible_units(instance, attribute, value):
77
"""
88
Validate if ``value`` has units compatible (in the sense of
99
:func:`~pinttr.units_compatible`) with ``attribute``.
10-
Only works with unit-enabled fields created with :func:`pinttr.ib`.
10+
11+
This validator checks that a Pint quantity has units compatible with the
12+
units declared for an attribute. It raises :class:`~pinttrs.exceptions.UnitsError`
13+
if the units are incompatible or if a unitless value is provided.
14+
15+
Only works with unit-enabled fields created with :func:`pinttrs.field` or
16+
:func:`pinttr.attrib`.
17+
18+
:param instance:
19+
The class instance being validated.
20+
21+
:param attribute:
22+
The attrs attribute being validated (must have units metadata).
23+
24+
:param value:
25+
The value to validate (should be a Pint quantity).
26+
27+
:raises UnitsError:
28+
If units are incompatible or if a unitless value is provided.
1129
"""
1230

1331
compatible_units = attribute.metadata[MetadataKey.UNITS]()

0 commit comments

Comments
 (0)