Skip to content

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

@belonesox

Description

@belonesox

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions