]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- Bug #891637, patch #1005466: fix inspect.getargs() crash on def foo((bar)).
authorMatthias Klose <doko@ubuntu.com>
Sun, 15 Aug 2004 17:16:25 +0000 (17:16 +0000)
committerMatthias Klose <doko@ubuntu.com>
Sun, 15 Aug 2004 17:16:25 +0000 (17:16 +0000)
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS

index bc6033328f4a86321117bfdb0a66924b2fc34291..87cc7f94fee8a233136ed166c027a80331b97af8 100644 (file)
@@ -621,14 +621,22 @@ def getargs(co):
                         count.append(value)
                     elif opname == 'STORE_FAST':
                         stack.append(names[value])
-                        remain[-1] = remain[-1] - 1
-                        while remain[-1] == 0:
-                            remain.pop()
-                            size = count.pop()
-                            stack[-size:] = [stack[-size:]]
-                            if not remain: break
+
+                        # Special case for sublists of length 1: def foo((bar))
+                        # doesn't generate the UNPACK_TUPLE bytecode, so if
+                        # `remain` is empty here, we have such a sublist.
+                        if not remain:
+                            stack[0] = [stack[0]]
+                            break
+                        else:
                             remain[-1] = remain[-1] - 1
-                        if not remain: break
+                            while remain[-1] == 0:
+                                remain.pop()
+                                size = count.pop()
+                                stack[-size:] = [stack[-size:]]
+                                if not remain: break
+                                remain[-1] = remain[-1] - 1
+                            if not remain: break
             args[i] = stack[0]
 
     varargs = None
index bdbec41ff458cf82730e9860d05d099c7cb20986..2f79fc3f1be5696b0bc0ebcf7e723cedff327a64 100644 (file)
@@ -374,3 +374,11 @@ test(defaults is None, 'A.m defaults')
 # Doc/lib/libinspect.tex claims there are 11 such functions
 count = len(filter(lambda x:x.startswith('is'), dir(inspect)))
 test(count == 11, "There are %d (not 11) is* functions", count)
+
+def sublistOfOne((foo)): return 1
+
+args, varargs, varkw, defaults = inspect.getargspec(sublistOfOne)
+test(args == [['foo']], 'sublistOfOne args')
+test(varargs is None, 'sublistOfOne varargs')
+test(varkw is None, 'sublistOfOne varkw')
+test(defaults is None, 'sublistOfOn defaults')
index d47fc96f99c2a882c7ba689bd463045bd3f21f95..3f02e0e9225f6c6d8e79d8d656671b00b0428ad6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -92,6 +92,8 @@ Library
 
 - Bug #934282: make pydoc.stripid() be case-insensitive.
 
+- Bug #891637, patch #1005466: fix inspect.getargs() crash on def foo((bar)).
+
 Build
 -----