Skip to content

Commit f7478d7

Browse files
authored
Merge pull request #34 from z-a-f/patch-1
Make the supported types an internal variable
2 parents d53a4b2 + cc56e10 commit f7478d7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

binarytree/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
_ATTR_RIGHT = "right"
3636
_ATTR_VAL = "val"
3737
_ATTR_VALUE = "value"
38+
_ATTR_VALUE_TYPES = (float, int)
3839
_SVG_XML_TEMPLATE = """
3940
<svg width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg">
4041
<style>
@@ -55,7 +56,7 @@
5556
</svg>
5657
"""
5758

58-
NodeValue = Union[float, int]
59+
NodeValue = Union[_ATTR_VALUE_TYPES]
5960

6061

6162
@dataclass
@@ -201,12 +202,12 @@ def __setattr__(self, attr: str, obj: Any) -> None:
201202
raise NodeTypeError("right child must be a Node instance")
202203

203204
elif attr == _ATTR_VALUE:
204-
if not isinstance(obj, (float, int)):
205+
if not isinstance(obj, _ATTR_VALUE_TYPES):
205206
raise NodeValueError("node value must be a float or int")
206207
object.__setattr__(self, _ATTR_VAL, obj)
207208

208209
elif attr == _ATTR_VAL:
209-
if not isinstance(obj, (float, int)):
210+
if not isinstance(obj, _ATTR_VALUE_TYPES):
210211
raise NodeValueError("node value must be a float or int")
211212
object.__setattr__(self, _ATTR_VALUE, obj)
212213

@@ -707,11 +708,11 @@ def validate(self) -> None:
707708
raise NodeTypeError(
708709
"invalid node instance at index {}".format(node_index)
709710
)
710-
if not isinstance(node.val, (float, int)):
711+
if not isinstance(node.val, _ATTR_VALUE_TYPES):
711712
raise NodeValueError(
712713
"invalid node value at index {}".format(node_index)
713714
)
714-
if not isinstance(node.value, (float, int)): # pragma: no cover
715+
if not isinstance(node.value, _ATTR_VALUE_TYPES): # pragma: no cover
715716
raise NodeValueError(
716717
"invalid node value at index {}".format(node_index)
717718
)

0 commit comments

Comments
 (0)