diff --git a/dcicutils/bundle_utils.py b/dcicutils/bundle_utils.py index de42c4280..0f9b73e1e 100644 --- a/dcicutils/bundle_utils.py +++ b/dcicutils/bundle_utils.py @@ -4,7 +4,7 @@ from .common import AnyJsonData from .env_utils import EnvUtils, public_env_name from .ff_utils import get_metadata -from .misc_utils import AbstractVirtualApp, ignored, ignorable, PRINT, to_camel_case +from .misc_utils import AbstractVirtualApp, ignored, ignorable, PRINT, remove_empty_properties, to_camel_case from .sheet_utils import ( LoadTableError, prefer_number, TabbedJsonSchemas, Header, Headers, TabbedHeaders, ParsedHeader, ParsedHeaders, TabbedParsedHeaders, SheetCellValue, TabbedSheetData, @@ -752,15 +752,3 @@ def load_items(filename: str, tab_name: Optional[str] = None, escaping: Optional override_schemas=override_schemas) return checked_items, problems return checked_items - - -def remove_empty_properties(data: Optional[Union[list, dict]]) -> None: - if isinstance(data, dict): - for key in list(data.keys()): - if (value := data[key]) in [None, "", {}, []]: - del data[key] - else: - remove_empty_properties(value) - elif isinstance(data, list): - for item in data: - remove_empty_properties(item) diff --git a/dcicutils/misc_utils.py b/dcicutils/misc_utils.py index 4582f9c0a..40b4d1604 100644 --- a/dcicutils/misc_utils.py +++ b/dcicutils/misc_utils.py @@ -1107,6 +1107,18 @@ def remove_suffix(suffix: str, text: str, required: bool = False): return text[:len(text)-len(suffix)] +def remove_empty_properties(data: Optional[Union[list, dict]]) -> None: + if isinstance(data, dict): + for key in list(data.keys()): + if (value := data[key]) in [None, "", {}, []]: + del data[key] + else: + remove_empty_properties(value) + elif isinstance(data, list): + for item in data: + remove_empty_properties(item) + + class ObsoleteError(Exception): pass