Skip to content
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

freeze(), unfreeze(), and nested key support #123

Closed
wants to merge 2 commits into from
Closed

freeze(), unfreeze(), and nested key support #123

wants to merge 2 commits into from

Conversation

Yves33
Copy link

@Yves33 Yves33 commented May 10, 2020

The following patch addresses issues 110 (and closely related 117) and 121
This is my first pull request! be indulgent!

#110 Deep setattr and gettattr when attribute names contain '.'
the patch enables
d=Dict()
var keypath='path.to.nested.key'
d[ keypath ]='test'
print(d [ keypass] )

#121 Is it possible to forbid accessing missing keys?
adict returns an empty dict when trying to access non existing keys
d=Dict()
assert d.a.b.c == {}
the patch introduces d.freeze() and d.unfreeze().
When the dict is frozen, you cannot create new keys (keyError raised) but you can modify existing ones
The patch overrides default get method to

  • get frozen/unfrozen state
  • freeze dict
  • return d[key] if key exists otherwise default
    -restore frozen/unfrozen state

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 1822161 on Yves33:master into 66d8811 on mewwts:master.

@evanjtravis
Copy link

Big fan of this PR.

@mewwts
Copy link
Owner

mewwts commented Sep 12, 2020

Hey! Can you split this PR into two where one has the freeze-functionality and another one for nested keys? In the new PR for nested keys, can you also outline the differences to this PR #119?
Thank you 🙏

@Yves33
Copy link
Author

Yves33 commented Sep 12, 2020 via email

@mewwts
Copy link
Owner

mewwts commented Sep 12, 2020

Thanks @Yves33!

Essentially - remove the nested keys functionality from here (deleted those changes), open another pull request with the nested keys functionality. I typically do this from the terminal, but looks like you might be using the built-in github editor?

@hellocoldworld
Copy link

I would love to see the freeze/unfreeze functionality.

@mewwts
Copy link
Owner

mewwts commented Nov 19, 2020

Closing this in favor of #130

@mewwts mewwts closed this Nov 19, 2020
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

Successfully merging this pull request may close these issues.

5 participants