Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bboerner opened this issue Jan 14, 2013 · 1 comment
Open

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

bboerner opened this issue Jan 14, 2013 · 1 comment

Comments

@bboerner
Copy link

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
@Dushistov
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants