Ulm-IQO / qudi-core

A framework for modular measurement applications.
GNU General Public License v3.0
25 stars 19 forks source link

[New Feature] add YAML constructor and representer for tuple #69

Closed qku closed 7 months ago

qku commented 9 months ago

Feature Description

Add a custom YAML constructor and representer for the built-in type tuple.

I found this SO post: https://stackoverflow.com/questions/9169025/how-can-i-add-a-python-tuple-to-a-yaml-file-using-pyyaml

Related Problem

Currently, when a tuple is dumped and loaded again, you get a list.

from qudi.util.yaml import yaml_dump, yaml_load

file = 'test.yml'
a = (1, 2, 3)

yaml_dump(file, a)
a_loaded = yaml_load(file)
assert a_loaded.isinstance(tuple)

Considered Alternatives

Rewriting classes such that they can handle both lists and tuples.

Additional Context

This is in the context of the ScanSettings data class in qudi-iqo-modules.

Contact Details

No response

qku commented 7 months ago

I suggest to close this. It is easily possible to convert lists to tuples at the point of use.