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

Autosave not triggered with list.extend() / list.append() #13

Open
PFython opened this issue Dec 12, 2020 · 2 comments
Open

Autosave not triggered with list.extend() / list.append() #13

PFython opened this issue Dec 12, 2020 · 2 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@PFython
Copy link
Owner

PFython commented Dec 12, 2020

When a CleverDict attribute or value is changed using "=" assignment it triggers the .save() method as intended.

list.append() and list.extend() do NOT trigger the autosave function however... not sure why, and I don't have any understanding of the internals, but just wondered if there it might be desirable/possible to specify a list of methods (outside of the CleverDict class) which, if called, would also trigger a mapped CleverDict method... mainly .save and .delete but could be other things as well.

That might be overly complicated, or it might provide another rich layer of cleverness to CleverDict. Please let me know your initial thoughts?

@PFython PFython closed this as completed Dec 12, 2020
@salabim
Copy link
Contributor

salabim commented Dec 12, 2020

I see that you have closed this issue, but I think it is not.

If I understand you well, you like to call the save method when the value in a CleverDict is updated with extend or append.
Well, that is not possible at all as the CleverDict object is not aware of the change of a mutable object.

The following program demonstrates that:

from cleverdict import CleverDict

class MyDict(CleverDict):
def save(self, k, v):
print(f'save[{k}] = {v}')
def init(self, *args, **kwargs):
super().init(**kwargs)

a = MyDict()
a[3]=4
l = [2,3]
a[1]= l
l.extend([4,5]) # this does not call the save method!
print(a)

I don't know what you mean when you say .extend works fine. But certainly not in this example.
Maybe you have to explain what you did accomplish with respct to .extend and save.

@PFython PFython reopened this Dec 14, 2020
@PFython PFython added enhancement New feature or request help wanted Extra attention is needed labels Jan 20, 2021
@PFython
Copy link
Owner Author

PFython commented Jan 30, 2021

Parked for now - it may even be an advantage to have .append() method able to bypass setting behaviour e.g. to avoid recursion issues in README example:

class AutoStore(CleverDict):
    def __init__(self, *args, **kwargs):
        self.setattr_direct('index', [])
        super().__init__(*args, **kwargs)

    def save(self, name, value):
        """ Keep a separate 'store' for data in .index """
        self.index.append((name, value))

Labelled as "wontfix" after Version 1.8.0 simply because the main authors don't currently have the time for non essential enhancements. If there's a huge uptake in people using CleverDict and asking for this feature that may change, or if you're reading this why not Fork, develop a solution, and contribute a Pull Request yourself?

@PFython PFython added wontfix This will not be worked on and removed help wanted Extra attention is needed labels Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants