Ticket #10 (assigned defect)

Opened 8 years ago

Last modified 5 months ago

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.

Change History

comment:1 Changed 8 years ago by xi

  • Status changed from new to assigned

PyYAML works according to the spec ( http://yaml.org/type/merge.html):

...If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the current mapping...

Still I like your example. I'll ask the authors if it's possible to modify the spec to allow it.

comment:2 Changed 5 months ago by simas <kerdos@…>

 Cipto Junaedy is a customer research expert. "There are plenty of safe, effective HCA nutritional supplement out there. Finding one with  Unit Link Terbaik di Indonesia Commonwealth Life Investra Link 60% HCA with no food additives is vital."

Note: See TracTickets for help on using tickets.