Skip to content

Commit

Permalink
Merge pull request #70 from kapsh/typecheck
Browse files Browse the repository at this point in the history
Support subclasses of builtin number types
  • Loading branch information
tbielawa committed Mar 20, 2018
2 parents 00fd53e + e0df96a commit e1a0364
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bitmath/__init__.py
Expand Up @@ -174,7 +174,7 @@ class Bitmath(object):
"""The base class for all the other prefix classes"""

# All the allowed input types
valid_types = [int, float, long]
valid_types = (int, float, long)

def __init__(self, value=0, bytes=None, bits=None):
"""Instantiate with `value` by the unit, in plain bytes, or
Expand Down Expand Up @@ -256,15 +256,15 @@ def _norm(self, value):
:param number value: The input value to be normalized
:raises ValueError: if the input value is not a type of real number
"""
if type(value) not in self.valid_types:
if isinstance(value, self.valid_types):
self._byte_value = value * self._unit_value
self._bit_value = self._byte_value * 8.0
else:
raise ValueError("Initialization value '%s' is of an invalid type: %s. "
"Must be one of %s" % (
value,
type(value),
", ".join([str(x) for x in self.valid_types])))
else:
self._byte_value = value * self._unit_value
self._bit_value = self._byte_value * 8.0
", ".join(str(x) for x in self.valid_types)))

##################################################################
# Properties
Expand Down

0 comments on commit e1a0364

Please sign in to comment.