sub-dictionary unavailable in constructor

Issue #56 invalid
potash
created an issue

(I posted the same issue on GitHub but I take it this is the right place.) Consider the following:

import yaml

def mapping_constructor(loader, node):
    args = loader.construct_mapping(node)
    print args
    return args

yaml.add_constructor('!tag', mapping_constructor)
print yaml.load('!tag {a: {b : c}}')

I expect the output to be

{'a': {'b': 'c'}}
{'a': {'b': 'c'}}

but instead I get:

{'a': {}}
{'a': {'b': 'c'}}

That is, the sub-dictionary doesn't get populated until after the constructor call. Is this by design? It makes it impossible to properly initialize objects whose args have dictionaries containing dictionaries. There is a similar issue with sub-lists, too, I think.

Comments (2)

  1. Log in to comment