extract frame check into function, usable by other modules
1 files changed, 8 insertions(+), 1 deletions(-)

M vanity/commander.py
M vanity/commander.py +8 -1
@@ 240,6 240,13 @@ def cleanopts(opts, dropkeys=None):
     return opts
 
 
+def firstframe():
+    """returns true if the type error was caused by the first
+    function call in the stack
+    """
+    return len(traceback.extract_tb(sys.exc_info()[2])) == 1
+
+
 class Command(object):
     """A thin class representing a command.
 

          
@@ 260,7 267,7 @@ class Command(object):
         try:
             return self.target(*args, **opts)
         except TypeError, err:
-            if len(traceback.extract_tb(sys.exc_info()[2])) == 1:
+            if firstframe():
                 raise InvalidArguments(self.name)
             raise