Closed hoytnix closed 8 years ago
Could you include the error message and stack trace?
Is this still a problem?
The following code resulted in the subsequent traceback for me when using the latest develop branch:
NotImplementedError: Dictionary class must be subclassed to use
Likewise, I received this similar error using the latest PyPi build:
NotImplementedError: List class must be subclassed to use
import yorm
from yorm.types import String, Integer, Float, Dictionary, List
@yorm.attr(name=String, number=Integer, gpa=Float, grades=List, foo=Dictionary)
@yorm.sync('my.json')
class Student:
def __init__(self, name, number, grades, foo):
self.name = name
self.number = number
self.gpa = 0.0
self.grades = grades
self.foo = foo
def main():
s = Student(name="John", number=42, grades=[0.15, 0.39, 0.78], foo={"bar": "spam"})
s.name = "John Doe"
if __name__ == '__main__':
main()
#manjaro@alisa:/mnt/my_home/Dev/Contrib/jacebrowning/yorm:[0]$ python json_test.py
Traceback (most recent call last):
File "json_test.py", line 21, in <module>
main()
File "json_test.py", line 16, in main
s = Student(name="John", number=42, grades=[0.15, 0.39, 0.78], foo={"bar": "spam"})
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/utilities.py", line 97, in modified_init
sync_object(self, path, attrs, **kwargs)
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/utilities.py", line 55, in sync_object
mapper.store()
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/mapper.py", line 29, in wrapped
return method(self, *args, **kwargs)
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/mapper.py", line 48, in wrapped
result = method(self, *args, **kwargs)
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/mapper.py", line 239, in store
data2 = converter.to_data(value)
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/types/containers.py", line 21, in to_data
value2 = cls.create_default()
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/bases/converter.py", line 36, in create_default
return cls.__new__(cls)
File "/mnt/my_home/Dev/Contrib/jacebrowning/yorm/yorm/types/containers.py", line 16, in __new__
raise NotImplementedError(msg)
NotImplementedError: Dictionary class must be subclassed to use
Currently, that error is expected. You need to tell it the type of the items in grades
.
Until https://github.com/jacebrowning/yorm/issues/58 is implemented, you need to extend the List
class to make a FloatList
(or Grades
) class.
@yorm.attr(name=String, number=Integer, gpa=Float, grades=List.of_type(Float)
^^^^^^^
In Json there are two data-types that are unknown to the mapper:
dicts:
lists: