munch.fromYAML issue
JohnV7 opened this issue · 1 comments
JohnV7 commented
In munch version 2.5.0 the funcation fromYAML requires as a first argument cls. This is not documented. What is it? Reference to some class?
Can you please give an example?
Thanks for this useful tool!
ayalash commented
@JohnV7 Thanks, I'm glad you like it.
The cls
argument is passed automatically by the python interpreter because fromYAML
was changed (from staticmethod
) to classmethod
.
The usage of this method didn't changed, you still call the method with the yaml string and gets Munch
object, from example:
yaml_str = 'foo:\n bar:\n - 1\n - 2\n hello: world\n'
obj = Munch.fromYAML(yaml_str)
The thing that version 2.5.0 added is that if you call it on one of the Munch
subclasses, the object will be created from them and not Munch
. For example:
yaml_str = 'foo:\n bar:\n - 1\n - 2\n hello: world\n'
default_value = None
obj = DefaultMunch.fromYAML(yaml_str, default_value)
assert type(obj) == DefaultMunch