MiniZinc / mzn-bench

A framework to performing benchmark testing on MiniZinc models, solvers, and/or the compiler itself.
https://www.minizinc.org
5 stars 5 forks source link

Cannot serialize `range` object #40

Closed hbierlee closed 1 year ago

hbierlee commented 1 year ago

Hi! I'm trying to fix an issue where ruamel (strangely) can't serialize range objects which are part of the MiniZinc model's output:

||     def represent_undefined(self, data: Any) -> None:
|| >       raise RepresenterError(f'cannot represent an object: {data!s}')
|| E       ruamel.yaml.representer.RepresenterError: cannot represent an object: range(1, 5)

I don't know why a python range is not a default registered class for ruamel, but adding yaml.register_class(range) also doesn't work:

|| self = <ruamel.yaml.representer.SafeRepresenter object at 0x7f529a523ee0>
|| tag = '!range', data = range(1, 5), cls = <class 'range'>, flow_style = None
||
||     def represent_yaml_object(
||         self, tag: Any, data: Any, cls: Any, flow_style: Any = None
||     ) -> MappingNode:
||         if hasattr(data, '__getstate__'):
||             state = data.__getstate__()
||         else:
|| >           state = data.__dict__.copy()
|| E           AttributeError: 'range' object has no attribute '__dict__'. Did you mean: '__dir__'?

Any ideas on how to fix it so ranges are serialized normally?

hbierlee commented 1 year ago

Should be fixed by https://github.com/MiniZinc/minizinc-python/pull/90