Ticket #40 (closed defect: worksforme)

Opened 7 years ago

Last modified 7 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?

Attachments Download (656 bytes) - added by dvd@… 7 years ago.
the test script

Change History

Changed 7 years ago by dvd@…

the test script

comment:1 Changed 7 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)

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.