fabiocaccamo / python-benedict

:blue_book: dict subclass with keylist/keypath support, built-in I/O operations (base64, csv, html, ini, json, pickle, plist, query-string, toml, xls, xml, yaml), s3 support and many utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

utility method clean does not work for nested dicts

martinius74 opened this issue · comments

Discussed in #382

Originally posted by martinius74 February 26, 2024
I was trying to clean my nested dictionaries from any empty string and collections, but somehow, it only considers the root level.
Nested keys are not cleaned.

Looking into the code, the method is using the keys() method.

def clean(d, strings=True, collections=True):
keys = list(d.keys())

If we would use the keypaths() method, it would be able to find all nested keys as well:

def clean(d, strings=True, collections=True):
keys = d.keypaths()

Would it make sense to change this behaviour?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

@martinius74 nice catch, I agree this should be the default behaviour, thank you for reporting this.

@martinius74 nice catch, I agree this should be the default behaviour, thank you for reporting this.

Thanks Fabio for picking it up!

@martinius74 you can upgrade to 0.33.2 version.