[pybank] Don't check for the exact type when checking arg types



commit 3122c8f099c08cf738093a82d2092428568bf466
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Wed May 13 17:11:22 2009 +0200

    Don't check for the exact type when checking arg types
---
 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:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]