Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with non-stringable keys — lets allow it, but just dont set attributes. #40

Open
belonesox opened this issue Oct 22, 2023 · 1 comment

Comments

@belonesox
Copy link

Lets consider an example:

from easydict import EasyDict as edict

adict_widh_non_str_keys_and_dicts_inside = {
    ('Lon', 'Arn'): {'a':1, 'b':2},
    ('Lon', 'Gou'): {'a':3, 'b':4},
}

aedict = edict(adict_widh_non_str_keys_and_dicts_inside)

Now we get exception:

… /site-packages/easydict/__init__.py", line 122, in __init__
    setattr(self, k, v)
TypeError: attribute name must be string, not 'tuple'

Obviously there is not mapping/processing for «non-stringable» keys,
and it is OK for top dict
but we still need EasyDict to transform nested dicts, etc.

So would be be great if:

  • Just dont set attributes if key is nonstringable (one line patch try/except, or something)
  • provide optional mapping functions as (EasyDict parameter) for such keys.
@belonesox belonesox changed the title Working with non-stringable keys — allow, but just dont set attributes. Working with non-stringable keys — lets allow it, but just dont set attributes. Oct 22, 2023
@leplatrem
Copy link
Collaborator

Thanks for reporting :)

I like both options... Don't hesitate to open a pull-requests with unit tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants