|
35 | 35 | _ATTR_RIGHT = "right" |
36 | 36 | _ATTR_VAL = "val" |
37 | 37 | _ATTR_VALUE = "value" |
| 38 | +_ATTR_VALUE_TYPES = (float, int) |
38 | 39 | _SVG_XML_TEMPLATE = """ |
39 | 40 | <svg width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg"> |
40 | 41 | <style> |
|
55 | 56 | </svg> |
56 | 57 | """ |
57 | 58 |
|
58 | | -NodeValue = Union[float, int] |
| 59 | +NodeValue = Union[_ATTR_VALUE_TYPES] |
59 | 60 |
|
60 | 61 |
|
61 | 62 | @dataclass |
@@ -201,12 +202,12 @@ def __setattr__(self, attr: str, obj: Any) -> None: |
201 | 202 | raise NodeTypeError("right child must be a Node instance") |
202 | 203 |
|
203 | 204 | elif attr == _ATTR_VALUE: |
204 | | - if not isinstance(obj, (float, int)): |
| 205 | + if not isinstance(obj, _ATTR_VALUE_TYPES): |
205 | 206 | raise NodeValueError("node value must be a float or int") |
206 | 207 | object.__setattr__(self, _ATTR_VAL, obj) |
207 | 208 |
|
208 | 209 | elif attr == _ATTR_VAL: |
209 | | - if not isinstance(obj, (float, int)): |
| 210 | + if not isinstance(obj, _ATTR_VALUE_TYPES): |
210 | 211 | raise NodeValueError("node value must be a float or int") |
211 | 212 | object.__setattr__(self, _ATTR_VALUE, obj) |
212 | 213 |
|
@@ -707,11 +708,11 @@ def validate(self) -> None: |
707 | 708 | raise NodeTypeError( |
708 | 709 | "invalid node instance at index {}".format(node_index) |
709 | 710 | ) |
710 | | - if not isinstance(node.val, (float, int)): |
| 711 | + if not isinstance(node.val, _ATTR_VALUE_TYPES): |
711 | 712 | raise NodeValueError( |
712 | 713 | "invalid node value at index {}".format(node_index) |
713 | 714 | ) |
714 | | - if not isinstance(node.value, (float, int)): # pragma: no cover |
| 715 | + if not isinstance(node.value, _ATTR_VALUE_TYPES): # pragma: no cover |
715 | 716 | raise NodeValueError( |
716 | 717 | "invalid node value at index {}".format(node_index) |
717 | 718 | ) |
|
0 commit comments