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

Improvement of class pyroSAR._dev_config.Storage #62

Closed
ibaris opened this issue Nov 13, 2018 · 1 comment
Closed

Improvement of class pyroSAR._dev_config.Storage #62

ibaris opened this issue Nov 13, 2018 · 1 comment

Comments

@ibaris
Copy link
Contributor

ibaris commented Nov 13, 2018

I found a way to improve our Storage class. With this we could allow only particular keys. this could help not to mess around with this class (look at __setattr__)

class Storage(dict):
     def __getattr__(self, name):
        try:
            return self[name]
        except KeyError:
            raise AttributeError(name)

    __delattr__ = dict.__delitem__

    KEYLIST = ['KEY1', 'KEY2', 'KEY3']

    def __repr__(self):
        if self.keys():
            m = max(map(len, list(self.keys()))) + 1
            return '\n'.join([k.rjust(m) + ': ' + repr(v)
                              for k, v in sorted(self.items())])
        else:
            return self.__class__.__name__ + "()"

    def __dir__(self):
        return list(self.keys())

    def __setattr__(self, key, value):
        if key not in Storage.KEYLIST:
            raise KeyError("{} is not a legal key of this Storage".format(repr(key)))
        dict.__setitem__(self, key, value)

What do you think?

@johntruckenbrodt
Copy link
Owner

The Storage class is no longer used and was removed from the code. See #305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants