diff --git a/ctapipe/core/config_writer.py b/ctapipe/core/config_writer.py index d2df93e95cc..dfdafb5816a 100644 --- a/ctapipe/core/config_writer.py +++ b/ctapipe/core/config_writer.py @@ -79,8 +79,12 @@ def _trait_to_str(trait, help=True, indent_level=0): trait_value = f"'{trait_value}'" # Make sure that list of values end up on multiple lines (In particular quality criteria) + # Since traitlets.List derivative can't be compared with it, nor list/tuple, I have to check if "List" is in the + # type (converted as str) value_repr = "" - if isinstance(trait_value, list): + trait_value_type = str(type(trait_value)) + trait_value_is_list = ("List" in trait_value_type) or isinstance(trait_value, list) + if trait_value_is_list: for v in trait_value: # tuples are not correctly handled by yaml, so we convert them to list here. They'll be converted to tuple # when reading again. @@ -92,7 +96,9 @@ def _trait_to_str(trait, help=True, indent_level=0): # Automatically comment all parameters that are unvalid commented = "" - if trait_value == traitlets.Undefined: + if trait_value in (traitlets.Undefined, None): + commented = "#" + elif trait_type.startswith("List") and len(trait_value) == 0: commented = "#" trait_repr += f"{indent_str*indent_level}{commented}{trait.name}: {value_repr}\n"