You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
> from attrdict import AttrDict
> a = AttrDict()
> isinstance(a, dict)
False
Is there a reason AttrDict is not extending dict? It also makes it impossible to use AttrDict as a "drop in" replacement in existing APIs.
Consider an API that used to return (or receive) a dict and could be switched to an AttrDict.
The text was updated successfully, but these errors were encountered:
AttrDict subclasses collections.MutableMapping which is what dict, collections.OrderedDict, collections.defaultdict, and collections.Counter all extend (incidentally none of those others subclass dict either). As far as I know, this is the recommended solution (perhaps a holdover from the time when it was impossible to subclass dict).
In most cases someone doing an insinstance(_, dict), people should probably be using insinstance(_, collections.Mapping) or insinstance(_, collections.MutableMapping). In the worst case scenario, you can always just cast it to a dict.
I've thus far avoided subclassing dict because I'm not convinced the remaining unimplemented methods are worth reducing the key-space. Which means I should probably reword it as "Can be used most places a dict can".
If you are in a situation in which you needAttrDict to subclass dict (or it would otherwise make things much easier), I'd very much appreciate it if you could comment on this issue (#21). The change would be somewhat bigger and I'm trying to gauge interest.
I'm going to close this issue as it's resolution/non-resolution will be the same as the linked issue.
The project description ready:
However, I discovered:
Is there a reason AttrDict is not extending dict? It also makes it impossible to use AttrDict as a "drop in" replacement in existing APIs.
Consider an API that used to return (or receive) a dict and could be switched to an AttrDict.
The text was updated successfully, but these errors were encountered: