8000 Additional "size" key being added to DotMap when converting from a nested dictionary · Issue #97 · drgrib/dotmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Additional "size" key being added to DotMap when converting from a nested dictionary #97

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

Open
philip928lin opened this issue Jun 27, 2023 · 2 comments

Comments

@philip928lin
Copy link
philip928lin commented Jun 27, 2023

When I convert a nested dictionary, it appears that additional items are added to the DotMap with the keys named "size" or "compute."
This sometimes causes the problem when doing "for k, v in DotMapObject.items():"
Those additional items will also stay when converting back to the dictionary.
Does anyone know why? and how to avoid that?

image
image

@FelixSchwarz
Copy link
Collaborator

Can you provide us with a code snippet that demonstrates the problem?

@templiert
Copy link

I think that OP made unwanted autovivifications by calling d.size or d.compute

from dotmap import DotMap

d = DotMap()
print(f"{"a" in d=}")
d.a
print(f"{"a" in d=}")

Output:

"a" in d=False
"a" in d=True

Use _dynamic=False

d = DotMap(_dynamic=False)
print(f"{"a" in d=}")
d.a

Output:

"a" in d=False
Traceback (most recent call last):
  File "C:\software\repos\myrepo\tests\dotmap_autovivification.py", line 10, in <module>
    d.a
  File "C:\software\miniforge\envs\myenv\Lib\site-packages\dotmap\__init__.py", line 125, in __getattr__
    raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{k}'") from None
AttributeError: 'DotMap' object has no attribute 'a'

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

3 participants
0