Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40174c3

Browse files
committed
SF bug #733667: kwargs handled incorrectly
The fast_function() inlining optimization only applies when there are zero keyword arguments.
1 parent ca2a2f1 commit 40174c3

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/test_extcall.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from test.test_support import verify, verbose, TestFailed, sortdict
22
from UserList import UserList
33

4+
def e(a, b):
5+
print a, b
6+
47
def f(*a, **k):
58
print a, sortdict(k)
69

@@ -22,6 +25,14 @@ def h(j=1, a=2, h=3):
2225
f(1, 2, 3, *(4, 5), **{'a':6, 'b':7})
2326
f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b':9})
2427

28+
# Verify clearing of SF bug #733667
29+
try:
30+
e(c=3)
31+
except TypeError:
32+
pass
33+
else:
34+
print "should raise TypeError: e() got an unexpected keyword argument 'c'"
35+
2536
try:
2637
g()
2738
except TypeError, err:

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,7 @@ fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)
34683468

34693469
PCALL(PCALL_FUNCTION);
34703470
PCALL(PCALL_FAST_FUNCTION);
3471-
if (argdefs == NULL && co->co_argcount == n &&
3471+
if (argdefs == NULL && co->co_argcount == n && nk==0 &&
34723472
co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
34733473
PyFrameObject *f;
34743474
PyObject *retval = NULL;

0 commit comments

Comments
 (0)