Custom Query (121 matches)

Filters
 
Or
 
  
 
Columns

Show under each result:


Results (13 - 15 of 121)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Ticket Resolution Summary Owner Reporter
#22 fixed Aliases break if there are temporary objects xi tim.hochberg@…

Reported by tim.hochberg@…, 8 years ago.

Description

If an object being passed to represet_data has a shorter lifespan than the representer, the results are unpredictable, but generally bad. In my case, I'm trying to represent a custom omap class. I register a representer like so:

def omap_representer(dumper, data):
    items = [[x, y] for (x, y) in data.iteritems()] 
    return dumper.represent_sequence(u'!omap', items)
    
yaml.add_representer(omap, omap_representer)

If I then dump something that contains multiple omaps, such as [one_omap,another_omap], the representer get's confused because it sees distinct objects that have the same id. Here's an actual example:

>>> a # Note that these are omaps not dictionaries, despite appearances.
[{1: 2, 2: 4}, {1: 99, 2: 88}]

>>> print yaml.dump(a)
- !omap
  - &id001 [1, 2]
  - &id002 [2, 4]
- !omap
  - *id001
  - *id002

Two approaches come to mind to fix this.

  1. Hold onto a reference to the original object as well as to the serialized object in represented_objects. This is what I did as a temporary fix.
  2. Do some sort of weak reference magic to track if an object dies and then delete it from represented_objects. This is more complicated and I'm not entirely sure it would work well. The upside is it's possibly more frugal with memory.

-tim

#23 fixed Dictionary output not sorted. xi tim.hochberg@…

Reported by tim.hochberg@…, 8 years ago.

Description

It is convenient to have YAML's output be consistent across runs. Some representers in PyYaml? do this already, but the dictionaries do not. I implemented a quick fix by replacing represent_dict with:

    def represent_dict(self, data):
        items = data.items()
        items.sort()
        return self.represent_mapping(u'tag:yaml.org,2002:map', items)

It might also be convenient to have custom sort orders as PyYaml? legacy does, but that's a bigger change.

#38 worksforme PySyck handles non-alphanumeric strings as references, others not xi thomas@…

Reported by thomas@…, 8 years ago.

Description
>>> 'a' is 'a'
True
>>> 'a.' is 'a.'
True
>>> syck.dump(['a', 'a'])
'--- \n- a\n- a\n'
>>> syck.dump(['a.', 'a.'])
'--- \n- &id001 a.\n- *id001\n'
>>>

the first two commands show that python itself doesn't distinguish. This is especially problematic since the second case produces a segmentation fault when using syck-0.55-r3 (and surely other older versions).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Note: See TracQuery for help on using queries.