in modular_sdk/commons/__init__.py [0:0]
def deep_pop(dct: dict, to_pop: dict) -> None:
for key, _to_pop in to_pop.items():
if not isinstance(_to_pop, (dict, list)):
dct.pop(key, None)
continue
# isinstance(_to_pop, (dict, list))
_dct = dct.get(key)
if type(_dct) != type(_to_pop):
continue
if isinstance(_to_pop, dict): # going deeper
deep_pop(_dct, _to_pop)
else: # isinstance(_to_pop, list)
for i, d in enumerate(_dct):
p = _to_pop[i] if len(to_pop) > i else None
if p:
deep_pop(d, p)