diff options
author | Tomeu Vizoso <tomeu@sugarlabs.org> | 2009-05-13 15:11:22 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@sugarlabs.org> | 2009-05-13 15:11:22 (GMT) |
commit | 3122c8f099c08cf738093a82d2092428568bf466 (patch) | |
tree | b2999283a18bb59ecdf130de739da88343cd1760 | |
parent | 199710d20348a68618ceccc784e9fe2b79c27727 (diff) |
Don't check for the exact type when checking arg types
-rw-r--r-- | bank/btypes.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/bank/btypes.py b/bank/btypes.py index d889920..34fd416 100644 --- a/bank/btypes.py +++ b/bank/btypes.py @@ -50,7 +50,9 @@ class Callable(object): repo.TYPE_TAG_INT16, repo.TYPE_TAG_UINT16, repo.TYPE_TAG_INT32): - if not isinstance(value, int): + try: + int(value) + except ValueError: raise TypeError("%s must be int, not %s" % (name, type(value).__name__)) if tag in (repo.TYPE_TAG_UINT, repo.TYPE_TAG_UINT8, @@ -60,7 +62,9 @@ class Callable(object): repo.TYPE_TAG_INT64, repo.TYPE_TAG_UINT64, repo.TYPE_TAG_ULONG): - if not isinstance(value, (int, long)): + try: + long(value) + except ValueError: raise TypeError("%s must be int or long, not %s" % (name, type(value).__name__)) if tag in (repo.TYPE_TAG_UINT32, repo.TYPE_TAG_UINT64, @@ -68,13 +72,17 @@ class Callable(object): raise TypeError("%s must be an unsigned value, not %s", name, value) elif tag in (repo.TYPE_TAG_FLOAT, repo.TYPE_TAG_DOUBLE): - if not isinstance(value, float): + try: + float(value) + except ValueError: raise TypeError("%s must be float, not %s" % (name, type(value).__name__)) elif tag == repo.TYPE_TAG_INTERFACE: # TODO pass elif tag == repo.TYPE_TAG_BOOLEAN: - if not isinstance(value, bool): + try: + bool(value) + except ValueError: raise TypeError("%s must be bool, not %s" % (name, type(value).__name__)) elif tag == repo.TYPE_TAG_ARRAY: if value is not None: |