This is working:
represent_dict_order = lambda self, data: self.represent_mapping('tag:yaml.org,2002:map', data.items())
yaml.add_representer(OrderedDict, represent_dict_order)
But gives me a PyCharm
warning: PEP8: do not assign a lambda expression, use a def
I follow the advice, but this is not working:
def represent_dict_order(self, data):
self.represent_mapping('tag:yaml.org,2002:map', data.items())
yaml.add_representer(OrderedDict, represent_dict_order)
I get:
yaml.emitter.EmitterError: expected NodeEvent, but got DocumentEndEvent()
I have two questions:
- Why is the
lambda
working and thedef
not? Aren't they supposed to be equivalent? - How can I stop
PyCharm
complaining about this specific error? I tried preceeding the lambda with#noinspection
but it is not recognized.