[Python-bugs-list] [ python-Bugs-733667 ] kwargs handled incorrectly
SourceForge.net
noreply@sourceforge.net
Sat, 17 May 2003 16:39:24 -0700
Bugs item #733667, was opened at 2003-05-07 01:10
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=733667&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
>Priority: 7
Submitted By: Andrew Dalke (dalke)
Assigned to: Jeremy Hylton (jhylton)
Summary: kwargs handled incorrectly
Initial Comment:
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 "<stdin>", line 1, in ?
File "<stdin>", 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 "<stdin>", line 1, in ?
TypeError: add() takes exactly 2 non-keyword arguments (1 given)
>>>
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-07 09:42
Message:
Logged In: YES
user_id=80475
Attaching a patch (actually a band-aid temporary fix).
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-07 05:37
Message:
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.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-07 04:23
Message:
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.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-07 02:54
Message:
Logged In: YES
user_id=80475
Ouch! This is a bad one. Bumping up the priority.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=733667&group_id=5470