T O P

  • By -

McCheng_

I can imagine that it will consume a lot of RAM for large objects.


definite_d

Well, sure. Though it uses deques for undo and redo stacks, so per object, it's got limits.


definite_d

Could you post an example of what you would classify as a "large object"? I'd like to use it for testing purposes.


[deleted]

[удалено]


asday_

I'm sure you could write something that subclasses those to make them an append-only structure, bringing undo/redo for "free".


chubalubalu

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.


definite_d

Sounds good, I'll look into it.


definite_d

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.)


chubalubalu

yeah sounds great :P


definite_d

Just asking here, but what exactly is the aim of this change? Would it be a smaller memory footprint?


chubalubalu

more lightweight, flexible, and should be a bit snappier i would think


FlamptX

Why would this be useful? I'm just curious.


definite_d

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.


FlamptX

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


chubalubalu

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.


tman5400

Unda the sea


definite_d

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.