Logging messages with dictionary args in Python 2.4b1 leads to exception

Stefan Behnel behnel_ml at dvs1.informatik.tu-darmstadt.de
Thu Oct 21 08:19:53 CEST 2004


Alex Martelli schrieb:
> log('msg %s', (1, 2, 3))
> 
> works w/o your patch but your patch breaks it, so it's not strictly true
> that there are no drawbacks, I believe.  Possibly the drawback's minor,
> though.

I just checked that, you're right.

"msg %s" % (1,2,3)

throws an exception, while

"msg %s" % ((1,2,3),)

does not.

It's maybe not that a common use case, I guess, but it's definitely a 
deviation from the original interface as in Python 2.3, so it breaks 
compatibility.

Maybe we still need a check for the actual type of args?

The only problematic case is a tuple as only argument, everything else 
should work. So there are three possible solutions for backward compatibility:

1) document the change :o)
2) check for a dictionary as first argument
3) check for a tuple as first argument

Since the tuple is the only problematic thing you could hand in, I 
personally feel a preference for making that the "exception" (i.e. I vote 
for 3).

Any comments?

Stefan



More information about the Python-list mailing list