Ticket #40 (closed defect: worksforme)

Opened 11 years ago

Last modified 11 years ago

incomplete dict constructor

Reported by: dvd@… Owned by: xi
Priority: normal Component: pyyaml
Severity: major Keywords:
Cc: dvd@…


Hi all,

I'm puzzled by a strange behavior of yaml

If you run the attached script you obtain an output like this:

{'date': '732638',
'fields': {},
'guid': '0000010f153544cf8a314808007f000000000001',
'expiration': None}
{'date': '732638',
'fields': {'': {}, 'it': {'title': 'Hello World'}},
'guid': '0000010f153544cf8a314808007f000000000001',
'expiration': None}

*Please note the 'fields' value (I wrap the output to increase legibility)*

the first line is printed inside this custom constructor function:

def news_constructor(loader, node):
    nodes = loader.construct_mapping(node)
    print nodes
    return nodes

the second line (the correct one) is the print of the return values of this function

Can you help me or explain me this strange behavior?


test-bug.py Download (656 bytes) - added by dvd@… 11 years ago.
the test script

Change History

Changed 11 years ago by dvd@…

the test script

comment:1 Changed 11 years ago by xi

  • Status changed from new to closed
  • Resolution set to worksforme

It's not a bug, it's a feature. :)

Dictionaries and other mutable structures are not constructed fully in order to support recursive structures.

If you still want to obtain a complete object, use the (undocumented) deep parameter of construct_mapping:

    nodes = loader.construct_mapping(node, deep=True)
Note: See TracTickets for help on using tickets.