Modify ↓
Ticket #10 (assigned defect)
merge map doesnt work as it should ... I think
| Reported by: | anonymous | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | |
| Cc: | tbrkic@… |
Description
Hi,
It seems that the user defined directives are ignore when just after the merge key.
I have the following yml code
Chip:
Name: "CHIPNAME"
RegSize: 4
<< : !include
file_name: ymlInclude2.yml
Where include is my own directive which just reads in a file
class Include(yaml.YAMLObject):
yaml_tag = '!include'
@classmethod
def from_yaml(cls, constructor, node):
# Convert the node to a dictionary
attributes = constructor.construct_mapping(node)
# Convert spaces into underlines
if attributes.has_key('file_name'):
common.log.info("We are reading in file: " + attributes['file_name'])
db = loadYAMLFile(attributes['file_name'])
# print db
return db
else:
raise KeyError, "!Include directive must have an attribute file_name"
@classmethod
def to_yaml(cls, representer, person):
pass # we havent implemented this
# Create mapping node
def __init__(self, file_name=None):
self.file_name = file_name
But the directive doesnt get called when I use the merge key. What I get when I run is this python structure.
{'Chip':
{'file_name': 'ymlInclude2.yml',
'Name': 'CHIPNAME', 'RegSize': 4},
'FormatVersion': 1}
So it seems that the directives are ignore when using the merge key.
Attachments
Note: See
TracTickets for help on using
tickets.

PyYAML works according to the spec ( http://yaml.org/type/merge.html):
Still I like your example. I'll ask the authors if it's possible to modify the spec to allow it.