Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot serialize range object #40

Closed
hbierlee opened this issue Oct 17, 2023 · 1 comment
Closed

Cannot serialize range object #40

hbierlee opened this issue Oct 17, 2023 · 1 comment

Comments

@hbierlee
Copy link
Contributor

hbierlee commented Oct 17, 2023

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
Copy link
Contributor Author

Should be fixed by MiniZinc/minizinc-python#90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant