dict != dict

5 views
Skip to first unread message

Petr Man

unread,
Oct 22, 2009, 3:24:16 AM10/22/09
to rp...@googlegroups.com
Hello,

I have encountered a bug (or a feature?) yesterday. One of my exposed
functions is returning a dictionary, which I pass as a to a local function as
**kwargs. That however causes an error:

Traceback (most recent call last):
File "client.py", line 92, in <module>
rparser.add_option(*args, **kwargs)
TypeError: add_option() argument after ** must be a dictionary

The kwargs variable _is_ a dictionary, or it definitely behaves like one
everywhere else except here. It just can't be upacked with **. I have
temporarily worked around this by pickling the dict on the server and
unpickling on the client, but I think that should not be necessary.
Am I missing something?

Petr

--
My GNUPG key is at http://petr.madnetwork.org/home/contact/pubkey.asc
Key fingerprint = 0F04 503F EF79 2B8D B63C 00B4 AD2F 0594 FAA5 0053

marcin....@gmail.com

unread,
Oct 22, 2009, 7:37:15 AM10/22/09
to Petr Man, rp...@googlegroups.com
Hi,

Not all python versions support a dictionary-like for ** (AFAIK 2.5.x does not!) so if type(kwargs) is not <type 'dict'>
This could be the problem:
see:
http://bugs.python.org/issue1686487



On Oct 22, 2009 3:24am, Petr Man <pe...@madnetwork.org> wrote:
> Hello,
>
>
>
> I have encountered a bug (or a feature?) yesterday. One of my exposed
>
> functions is returning a dictionary, which I pass as a to a local function as
>
> **kwargs. That however causes an error:
>
>
>
> Traceback (most recent call last):
>
>  File "client.py", line 92, in
>

tomer filiba

unread,
Oct 22, 2009, 11:59:13 AM10/22/09
to rp...@googlegroups.com
yes, ** might not be able to extract dict-like objects.
to overcome it, use the following (harmless) trick:

x = .... # remote dict
f(**dict(x))

dict(dict_like_object) will return a real dict that you can expand with **



-tomer


An NCO and a Gentleman

Petr Man

unread,
Oct 23, 2009, 3:34:17 AM10/23/09
to rp...@googlegroups.com
Good morning,
thank you both for clarification.
Petr

On Thu, Oct 22, 2009 at 05:59:13PM +0200, tomer filiba wrote:
>
> x = .... # remote dict
> f(**dict(x))
>

Reply all
Reply to author
Forward
0 new messages