Issue 733667: kwargs handled incorrectly (original) (raw)

I'm using Python2.3 (first with a1 then tested with CVS version "Python 2.3b1+ (#7, May 6 2003, 23:41:12)" compiled a few minutes ago).

There's a bug in how it handles an error condition with keyword arguments. Here's a reproducible

Python 2.3b1+ (#7, May 6 2003, 23:41:12) [GCC 3.1 20020420 (prerelease)] on darwin Type "help", "copyright", "credits" or "license" for more information.

def add(a, b): ... print "add", repr(a), repr(b) ... return a + b ... add(a=3) add 'a' 3 Traceback (most recent call last): File "", line 1, in ? File "", line 3, in add TypeError: cannot concatenate 'str' and 'int' objects

The expected behaviour is what Python 2.2 does, which is

def add(a, b): ... return a + b ... add(a=3) Traceback (most recent call last): File "", line 1, in ? TypeError: add() takes exactly 2 non-keyword arguments (1 given)

Logged In: YES user_id=80475

def f(a,b): print a, b

def g(a,b,**kw): print a, b, kw

f(c=3) # prints c 3 g(c=3) # raises correct error for non-keyword arguments.

So, the restated version of the problem is that: when keyword arguments are passed to a function not defining **kw, then the keyword in interpreted as a single for the first positional argument and the keyword value as the second positional argument.

Weird and bad!

Reverting to earlier versions of getargs.c did not help.
Likewise the dict(red=3, blue=4) patch is not the culprit. The prime suspect is now the function call optimizations.

Logged In: YES user_id=80475

Jeremy, it looks like this bug was part of your patches on 2/5/2003. CVS runs the code the day before, but not on the day after.

The culprit is likely in taking the fast_function() path which bypasses the usual keyword argument handling. See ceval.c 2.348 and the related changes to sysmodule.c and ceval.h.