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

Add freeze method (to make the dict immutable). #71

Open
fabiocaccamo opened this issue Jan 5, 2022 · 1 comment
Open

Add freeze method (to make the dict immutable). #71

fabiocaccamo opened this issue Jan 5, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Jan 5, 2022

Fund with Polar
@fabiocaccamo fabiocaccamo added the enhancement New feature or request label Jan 5, 2022
@fabiocaccamo fabiocaccamo self-assigned this Jan 5, 2022
@fabiocaccamo fabiocaccamo moved this to Todo in Open Source Dec 1, 2022
@thesayfulla
Copy link

Hello, is it possible to add an attribute to a benedict? I wanted to add an is_frozen attribute, but I encountered an error like this:

    raise AttributeError(attr_message) from None
AttributeError: 'benedict' object has no attribute 'is_frozen'

I've written:

class benedict(KeyattrDict, KeypathDict, IODict, ParseDict):
    def __init__(self, *args, **kwargs):
        ....
        self.is_frozen = False

    def freeze(self):
        self.is_frozen = True
        
    def __setitem__(self, key, value):
        if self.is_frozen:
            raise TypeError("This dictionary is immutable")
        return super().__setitem__(key, self._cast(value))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants