summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_extcall.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-03-30 23:55:31 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-03-30 23:55:31 (GMT)
commit074c3e62d155349a69442f43e81a73883f222ea9 (patch)
tree50a773b1a903857944554bb06372decdf5addb3d /Lib/test/test_extcall.py
parentaaf0ab26ed4fd02da874a9d2eee68b7c64e8377d (diff)
downloadcpython-074c3e62d155349a69442f43e81a73883f222ea9.zip
cpython-074c3e62d155349a69442f43e81a73883f222ea9.tar.gz
cpython-074c3e62d155349a69442f43e81a73883f222ea9.tar.bz2
Two fixes for extended call syntax:
If a non-tuple sequence is passed as the *arg, convert it to a tuple before checking its length. If named keyword arguments are used in combination with **kwargs, make a copy of kwargs before inserting the new keys.
Diffstat (limited to 'Lib/test/test_extcall.py')
-rw-r--r--Lib/test/test_extcall.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 9b5994d..74d9ef2 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -46,6 +46,50 @@ g(1)
g(1, 2)
g(1, 2, 3)
g(1, 2, 3, *(4, 5))
+class Nothing: pass
+try:
+ g(*Nothing())
+except AttributeError, attr:
+ assert attr[0] == '__len__'
+else:
+ print "should raise AttributeError: __len__"
+
+class Nothing:
+ def __len__(self):
+ return 5
+try:
+ g(*Nothing())
+except AttributeError, attr:
+ assert attr[0] == '__getitem__'
+else:
+ print "should raise AttributeError: __getitem__"
+
+class Nothing:
+ def __len__(self):
+ return 5
+ def __getitem__(self, i):
+ if i < 3:
+ return i
+ else:
+ raise IndexError, i
+g(*Nothing())
+
+# make sure the function call doesn't stomp on the dictionary?
+d = {'a': 1, 'b': 2, 'c': 3}
+d2 = d.copy()
+assert d == d2
+g(1, d=4, **d)
+print d
+print d2
+assert d == d2, "function call modified dictionary"
+
+# what about willful misconduct?
+def saboteur(**kw):
+ kw['x'] = locals()
+d = {}
+saboteur(a=1, **d)
+assert d == {}
+
try:
g(1, 2, 3, **{'x':4, 'y':5})
except TypeError, err: