-
Notifications
You must be signed in to change notification settings - Fork 118
why does AttrMap return a tuple when a list is stored? #34
Comments
m["a"] by the way returns the list however |
AttrDict also return tuple |
I started using this in a project, and now I regret it because of this behavior, which is completely fucked. This is Python. You don't silently change the type of objects passed to a data structure! Not to mention it's not even consistent.
my mistake for assuming something simple like this would have been executed without huge pitfalls. |
While I'm not sure what the justification is for this behavior by default, it's very easily worked-around. It takes longer to post a complaint on Github than to look at the method signatures to find out how to change the undesired behavior. The constructors for >>> m = AttrMap(sequence_type=list)
>>> m.l = [1, 2, 3]
>>> m.l
[1, 2, 3]
>>> type(m.l)
<class 'list'> Strangely, >>> d = AttrDict()
>>> d._setattr('_sequence_type', list)
>>> d.l = [1, 2, 3]
>>> d.l
[1, 2, 3]
>>> type(d.l)
<class 'list'> |
Thanks so this might be solved |
I have a problem accessing an xarray.Dataset object which, when returned, is converted to an attrdict.dictionary.AttrDict. I really want to suppress this behaviour. |
Its the _build method that changes the types so I have simply patched it like so:
This means that you can only access attributes to the first dot (no foo.bar.hello.world) but that is all I need and want. |
jeffkayser's solution is helpful for the special case, but the general problem remains:
This is a genuine bug. |
jeff Kayser's solution does not in fact workl
|
Thanks jonathanStrong. Backatcha. It's new, so comments welcome. #from attrdict import AttrDict verbose=False
if name=='main':
|
return (1,2,3)
This sould not happen, right? Would be really good to fix this :-)
Thanks 👍
The text was updated successfully, but these errors were encountered: