Skip to content

Tagged types can not be nested #8

Description

@jcea

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}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions