Functions does not accept keyword arguments if an argument list specified

Létezõ letezo at fw.hu
Sun Feb 16 17:17:39 EST 2003


I faced with "interesting" behaviour of Python 2.2.1. Functions does not
accept keyword arguments if an argument list specified. Interactive session:

ActivePython 2.2.1 Build 222 (ActiveState Corp.) based on
Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def fn(*args,**kw): print 'args=%r, kw=%r'%(args,kw)
...
>>> fn(1,2,a=3,b=4)
args=(1, 2), kw={'a': 3, 'b': 4}
>>> al=[1,2]
>>> kd={'a':3,'b':4}
>>> fn(*al,**kd)
args=(1, 2), kw={'a': 3, 'b': 4}
>>> fn(1,2,**kd)
args=(1, 2), kw={'a': 3, 'b': 4}
>>> fn(*al,a=3,b=4)
  File "<stdin>", line 1
    fn(*al,a=3,b=4)
           ^
SyntaxError: invalid syntax

It's valid to apply a keyword dictionary and an argument list at the same
time. Keyword dictionary can be applied with real arguments. Python should
allow applying an argument list while passing real keyword arguments. As far
as I know, it should cause no ambiguous syntax.

Opinions?

- Complex -







More information about the Python-list mailing list