cbor_py icon indicating copy to clipboard operation
cbor_py copied to clipboard

Tagged types can not be nested

Open jcea opened this issue 7 years ago • 1 comments

Tagged types using cbor.TagMapper() can not be nested:

#!/usr/bin/env python3

import cbor
from collections import namedtuple

test = namedtuple('test', 'x y')

cbor_test = cbor.ClassTag(15309737, test, tuple, lambda x: test(*x))
cbor_set = cbor.ClassTag(15309738, set, tuple, lambda x: set(x))
mapper = cbor.TagMapper(class_tags=(cbor_test, cbor_set),
                        raise_on_unknown_tag=True)
x = {7:test(1,{1,2,3})}
y = mapper.loads(mapper.dumps(x))

print(y == x)


Traceback (most recent call last):
  File "./z.py", line 13, in <module>
    y = mapper.loads(mapper.dumps(x))
  File "/usr/local/lib/python3.6/site-packages/cbor/tagmap.py", line 99, in dumps
    return dumps(self.encode(obj))
ValueError: cannot serialize unknown object: {1, 2, 3}

jcea avatar Dec 14 '17 01:12 jcea

I have a patch for this. Should I do a pull request here or in BitBucket?

jcea avatar Dec 14 '17 01:12 jcea