Skip to content

utils

remove_unexpected_keys_from_dictionary(dictionary, expected_keys)

This function mutates input dictionary

Source code in inference/core/workflows/core_steps/common/utils.py
406
407
408
409
410
411
412
413
414
def remove_unexpected_keys_from_dictionary(
    dictionary: dict,
    expected_keys: set,
) -> dict:
    """This function mutates input `dictionary`"""
    unexpected_keys = set(dictionary.keys()).difference(expected_keys)
    for unexpected_key in unexpected_keys:
        del dictionary[unexpected_key]
    return dictionary