Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Why must ctor args be a dict or list? #20

Open
bboerner opened this Issue · 0 comments

1 participant

@bboerner

This:

class datetime(object):
    def __init__(self, args):
        self.args = args

    def __str__(self):
        return self.args

jsonrpclib.config.classes.add(datetime)

x = { "__jsonclass__": ["datetime", "2013-01-10T22:22:20"] }
result = jsonclass.load(x)
print "x: %s, result: %s" % (x, result)

returns:

# Traceback (most recent call last):
#   File ".\test.py", line 59, in <module>
#     result = jsonclass.load(x)
#   File "c:\Python27\lib\site-packages\jsonrpclib\jsonclass.py", line 140, in load
#     raise TranslationError('Constructor args must be a dict or list.')
# jsonrpclib.jsonclass.TranslationError: Constructor args must be a dict or list.

Why not this?

diff -u -r1.1 jsonclass.py
--- jsonclass.py        2013/01/14 21:51:58     1.1
+++ jsonclass.py        2013/01/14 21:52:14
@@ -137,7 +137,7 @@
     elif type(params) is types.DictType:
         new_obj = json_class(**params)
     else:
-        raise TranslationError('Constructor args must be a dict or list.')
+        new_obj = json_class(params)
     for key, value in obj.iteritems():
         if key == '__jsonclass__':
             continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.