-
Notifications
You must be signed in to change notification settings - Fork 3
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
Nested records become generic dict
in otypes
#38
Comments
After reviewing moo code it appears that this behavior is intentional, for better or worse. A record field object is actually stored in the record object as an It's actually a trivial change to make a For example, a So, allowing Really, having At the end, I think the only difference we are talking about here is allowing Perhaps the solution is to adopt or develop some kind of POD-to-object converter? Something simple based on use of Here is an interesting hack I found: https://stackoverflow.com/a/15882327 import json
from collections import namedtuple
pod = ab.pod()
print(pod)
# {'a': {'name': 'name'}, 'b': {'count': 42}}
jtext = json.dumps(pod)
ab2 = json.loads(jtext, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
print (ab2)
# X(a=X(name='name'), b=X(count=42))
print (ab2.b.count)
# 42 Perhaps something slightly fancier which can use a more relevant name than |
@plasorak reports that a record held in the field of another record becomes represented merely as a
dict
when the parent record is instantiated throughotypes
.That last line asserts with:
The text was updated successfully, but these errors were encountered: