-
-
Notifications
You must be signed in to change notification settings - Fork 133
Closed
Description
- cattrs version: 1.0.0
- Python version: Python 3.6
- Operating System: Linux (Fedora)
Description
Right now, cattr.structure will silently ignore extra keys when structuring into an attrs object:
In [1]: import attr
...: import cattr
...:
...: @attr.s
...: class A:
...: a: int = attr.ib()
...:
...: cattr.structure({"a": 1, "b": 2}, A)
Out[1]: A(a=1)I assume this is intended behavior (since I believe this changed since cattrs 0.9), but it'd be nice to have an option to throw an error on extra keys instead.
In our particular use-case, we are using cattrs and attrs to verify some configuration files we are using, some of which have default keys:
@attr.s
class Config:
some_key: int = attr.ib(default=0)
b/c of this "silently allow extra keys" behavior, cattr.structure doesn't catch typos (e.g. some_key vs sme_key), because it will just ignore the incorrectly-typed key and use the default value for the substitute.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels