id	summary	reporter	owner	description	type	status	priority	component	severity	resolution	keywords	cc
252	Sub-classing yaml.YAMLObject bypasses __init__	ijmcfadyen@…	xi	"Hello

I really like the idea of the YAML constructor that allows you to auto-magically create class instances by simply loading YAML.

In the example shown in the documentation for constructors, the ""Monster"" class sub-classes yaml.YAMLObject and includes an __init__() method.

However, in practice the __init__() is never called. YAMLObject.from_yaml() calls the loader.construct_yaml_object() method, which directly inserts the mapping into the instance's __dict__.

So why does the example code show an __init__() method setting the attributes of the instance?

More importantly, this means that there is no way to use __init__ to define the full set of fields that are expected, and supply default values if they are missing from the YAML. So if I have a dozen YAML files, every one of them has to have the exact same set of fields, even if some or most of the files have either no value or a simple default value for one or more fields.

In my opinion, this greatly reduces the utility of this approach - but perhaps I am missing something here? 

Thanks"	defect	new	normal	pyyaml	normal			
