order of kwargs reversed

18 views
Skip to first unread message

sander koelstra

unread,
Mar 12, 2013, 11:05:15 PM3/12/13
to torna...@googlegroups.com
Hi,

I've noticed some strange behaviour with tornadorpc, not sure if I'm doing something wrong though.


server code:

from tornadorpc.json import JSONRPCHandler
from tornadorpc import start_server
class Handler(JSONRPCHandler):
    def test(self, a=1, b=2, c=3, d=4):
        return {'a': a, 'b': b, 'c': c, 'd': d}
start_server(Handler, port=8888)


client code:

import jsonrpclib
server = jsonrpclib.Server('http://localhost:8888')
print server.test()
print server.test(a='one')
print server.test(d='four')
print server.test(a='one',b='two',c='three',d='four')

This prints (unicode markers removed for readability):
{'a': 4, 'c': 2, 'b': 3, 'd': 1}
{'a': 'one', 'c': 2, 'b': 3, 'd': 1}
{'a': 4, 'c': 2, 'b': 3, 'd': 'four'}
{'a': 'one', 'c': 'three', 'b': 'two', 'd': 'four'}

so it seems that the order of unset kwargs gets reversed somehow!
any clue what's going on here?

Thanks,
Sander

sander koelstra

unread,
Mar 12, 2013, 11:23:13 PM3/12/13
to torna...@googlegroups.com
Seems to go wrong in util.py:

if defaults:
    reverse_args = args[:]
    reverse_args.reverse()
    for i in range(len(defaults)):
        arg_key = reverse_args[i]
        final_kwargs.setdefault(arg_key, defaults[i])

the arguments are purposefully reversed, what is the rationale there?
commenting reverse_args.reverse() solves my problem, but I still don't understand why this is there...

sander koelstra

unread,
Mar 13, 2013, 9:28:32 AM3/13/13
to torna...@googlegroups.com
I've created a pull request with a fix for this on github
Reply all
Reply to author
Forward
0 new messages