Ticket #40 (closed defect: worksforme)
incomplete dict constructor
| Reported by: | dvd@… | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | major | Keywords: | |
| Cc: | dvd@… |
Description
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
Change History
Changed 6 years ago by dvd@…
-
attachment
test-bug.py
added
comment:1 Changed 6 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)

the test script