Dump of sets always tries to sort, even when sorting is not possible.

Issue #31 new
Robbie Coomber
created an issue

For example. try the following code:

>>> yaml.dump({frozenset(), 1})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/yaml/__init__.py", line 202, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/usr/lib64/python2.7/site-packages/yaml/__init__.py", line 190, in dump_all
  File "/usr/lib64/python2.7/site-packages/yaml/representer.py", line 28, in represent
    node = self.represent_data(data)
  File "/usr/lib64/python2.7/site-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib64/python2.7/site-packages/yaml/representer.py", line 229, in represent_set
    return self.represent_mapping(u'tag:yaml.org,2002:set', value)
  File "/usr/lib64/python2.7/site-packages/yaml/representer.py", line 120, in represent_mapping
TypeError: can only compare to a set

Maybe the TypeError could be caught, and the unsorted values are used?

Comments (0)

  1. Log in to comment