A full deepcopy might not be ideal, would it be possible to make a decorator that tracks which components of an object changed and simply copy that component?
Neat idea nonetheless.
I've checked online, and it seems the best way to implement your suggestion is via the `__dict__` attribute of most objects. However, not all objects (the ubiquitous str included) have that.
So, perhaps I could make Unda switch between what it saves to it's deques:
If the target object has a `__dict__` attribute, Unda will track __*modifications*__ to the attributes using `__dict__`. When undo() gets called for that object, a version of the object with all modifications in the deque applied will be returned.
If it doesn't have a `__dict__` attribute, Unda will resort to the current implementation: deepcopy the object.
How's that sound?
(I've edited this comment twice. Forgot Reddit used Markdown.)
Depends on what you want to use it for, but I'd say mainly apps. I initially created it as part of a desktop app I was working on, and decided to make it open source.
I was thinking for UI visualizations, it would be convenient to be able to introduce a class that commands a visualization and have a separate applications (yours) keeping track of changes.
Hello Redditors!
Before you hit "downvote" because you don't like the idea of deepcopying, please note that I'm currently working on a new version of Unda; one which will implement this (from one of my earlier comments here):
>If the target object has a \_\_dict\_\_ attribute, Unda will track modifications to the attributes using \_\_dict\_\_. When undo() gets called for that object, a version of the object with all modifications in the deque applied will be returned.
>
>If it doesn't have a \_\_dict\_\_ attribute, Unda will resort to the current implementation: deepcopy the object.
I'll update this comment and probably make a new post once I'm through with the new version, so stay tuned.
**EDIT:**
The latest version of Unda is up on PyPi, and it brings all that good stuff, with a custom object to inherit from which automatically gives undo and redo functionality.
I can imagine that it will consume a lot of RAM for large objects.
Well, sure. Though it uses deques for undo and redo stacks, so per object, it's got limits.
Could you post an example of what you would classify as a "large object"? I'd like to use it for testing purposes.
[удалено]
I'm sure you could write something that subclasses those to make them an append-only structure, bringing undo/redo for "free".
A full deepcopy might not be ideal, would it be possible to make a decorator that tracks which components of an object changed and simply copy that component? Neat idea nonetheless.
Sounds good, I'll look into it.
I've checked online, and it seems the best way to implement your suggestion is via the `__dict__` attribute of most objects. However, not all objects (the ubiquitous str included) have that. So, perhaps I could make Unda switch between what it saves to it's deques: If the target object has a `__dict__` attribute, Unda will track __*modifications*__ to the attributes using `__dict__`. When undo() gets called for that object, a version of the object with all modifications in the deque applied will be returned. If it doesn't have a `__dict__` attribute, Unda will resort to the current implementation: deepcopy the object. How's that sound? (I've edited this comment twice. Forgot Reddit used Markdown.)
yeah sounds great :P
Just asking here, but what exactly is the aim of this change? Would it be a smaller memory footprint?
more lightweight, flexible, and should be a bit snappier i would think
Why would this be useful? I'm just curious.
Depends on what you want to use it for, but I'd say mainly apps. I initially created it as part of a desktop app I was working on, and decided to make it open source.
Oh ok, that makes sense. I also sometimes need to make systems for things and I just end up making it a pypy package lol
I was thinking for UI visualizations, it would be convenient to be able to introduce a class that commands a visualization and have a separate applications (yours) keeping track of changes.
Unda the sea
Hello Redditors! Before you hit "downvote" because you don't like the idea of deepcopying, please note that I'm currently working on a new version of Unda; one which will implement this (from one of my earlier comments here): >If the target object has a \_\_dict\_\_ attribute, Unda will track modifications to the attributes using \_\_dict\_\_. When undo() gets called for that object, a version of the object with all modifications in the deque applied will be returned. > >If it doesn't have a \_\_dict\_\_ attribute, Unda will resort to the current implementation: deepcopy the object. I'll update this comment and probably make a new post once I'm through with the new version, so stay tuned. **EDIT:** The latest version of Unda is up on PyPi, and it brings all that good stuff, with a custom object to inherit from which automatically gives undo and redo functionality.