title: Is there a way to construct an object using PyYAML construct_mapping after all nodes complete loading?
body: <p>I am trying to make a yaml sequence in python that creates a custom python object. The object needs to be constructed with dicts and lists that are deconstructed after <code>__init__</code>. However, it seems that the construct_mapping function does not construct the entire tree of embedded sequences (lists) and dicts.<br>
  Consider the following:</p>
  
  <pre><code>import yaml
  
  class Foo(object):
      def __init__(self, s, l=None, d=None):
          self.s = s
          self.l = l
          self.d = d
  
  def foo_constructor(loader, node):
      values = loader.construct_mapping(node)
      s = values["s"]
      d = values["d"]
      l = values["l"]
      return Foo(s, d, l)
  yaml.add_constructor(u'!Foo', foo_constructor)
  
  f = yaml.load('''
  --- !Foo
  s: 1
  l: [1, 2]
  d: {try: this}''')
  
  print(f)
  # prints: 'Foo(1, {'try': 'this'}, [1, 2])'
  </code></pre>
  
  <p>This works fine because <code>f</code> holds the references to the <code>l</code> and <code>d</code> objects, which are actually filled with data <strong>after</strong> the <code>Foo</code> object is created.</p>
  
  <p>Now, let's do something a smidgen more complicated:</p>
  
  <pre><code>class Foo(object):
      def __init__(self, s, l=None, d=None):
          self.s = s
          # assume two-value list for l
          self.l1, self.l2 = l
          self.d = d
  </code></pre>
  
  <p>Now we get the following error</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 27, in &lt;module&gt;
      d: {try: this}''')
    File "/opt/homebrew/lib/python2.7/site-packages/yaml/__init__.py", line 71, in load
      return loader.get_single_data()
    File "/opt/homebrew/lib/python2.7/site-packages/yaml/constructor.py", line 39, in get_single_data
      return self.construct_document(node)
    File "/opt/homebrew/lib/python2.7/site-packages/yaml/constructor.py", line 43, in construct_document
      data = self.construct_object(node)
    File "/opt/homebrew/lib/python2.7/site-packages/yaml/constructor.py", line 88, in construct_object
      data = constructor(self, node)
    File "test.py", line 19, in foo_constructor
      return Foo(s, d, l)
    File "test.py", line 7, in __init__
      self.l1, self.l2 = l
  ValueError: need more than 0 values to unpack
  </code></pre>
  
  <p>This is because the yaml constructor is starting at the outer layer of nesting before and constructing the object before all nodes are finished. Is there a way to reverse the order and start with deeply embedded (e.g. nested) objects first? Alternatively, is there a way to get construction to happen at least <em>after</em> the node's objects have been loaded? </p>