in probe_scraper/parsers/repositories.py [0:0]
def remove_none(obj):
"""
Recursively traverses a dict or list, removing all dict items where the value
is None. This helps us meet the existing probeinfo API contract and sidesteps
an awkward incompatibility between JSON schemas and OpenAPI schemas, which use
incompatible constructs for marking fields as nullable.
Implementation from https://stackoverflow.com/a/20558778
"""
if isinstance(obj, (list, tuple, set)):
return type(obj)(remove_none(x) for x in obj if x is not None)
elif isinstance(obj, dict):
return type(obj)(
(remove_none(k), remove_none(v))
for k, v in obj.items()
if k is not None and v is not None
)
else:
return obj