Hello,
I've noticed that using .append() on a PickleShare Key does not represent the changes that were made.
Example
Command Line 1:
>>> db = PickleShareDB('C:\\Users\\NULL\\AppData\\Local\\Temp\\test')
>>> db['stack'] = []
>>> db['stack']
[]
Command Line 2:
>>> db = PickleShareDB('C:\\Users\\NULL\\AppData\\Local\\Temp\\test')
>>> db['stack']
[]
Command Line 1:
>>> db['stack'].append("Hello World!")
>>> db['stack']
['Hello World!']
Command Line 2:
In fact, I added my own debugging, and the .append() does not even trigger the __setitem__ function of the PickleShareDB class.
>>> from pickleshare import *
>>> db = PickleShareDB('test')
This is the debugged version.
>>> db['testvalue'] = 1234567
Set item called with key:testvalue and value:1234567
>>> db['stack'] = []
Set item called with key:stack and value:[]
>>> db['stack'].append("Hello")
Fix
Since the __setitem__ magic method only triggers when the value of a key is set, or updated, it does not trigger when you .append() something.
Also, there is no magic method that triggers when an .append() happens
So I suggest adding an .append() function:
def append(self, key, value):
currentValue = self[key]
currentValue.append(value)
updatedValue = currentValue
self[key] = updatedValue
Test
Command Line 1:
>>> db = PickleShareDB('C:\\Users\\NULL\\AppData\\Local\\Temp\\test')
>>> db['stack'] = []
>>> db['stack']
[]
Command Line 2:
>>> db = PickleShareDB('C:\\Users\\NULL\\AppData\\Local\\Temp\\test')
>>> db['stack']
[]
Command Line 1:
>>> db.append('stack', 'Hello World!')
>>> db['stack']
['Hello World!']
Command Line 2:
>>> db['stack']
['Hello World!']
It would be nice if you could overwrite the default .append() function, like db['stack'].append(0) but since every db['key'] is not an instance of the class PickleShareDB but a list, I don't want to mess with it :D
Hello,
I've noticed that using
.append()on a PickleShare Key does not represent the changes that were made.Example
Command Line 1:
Command Line 2:
Command Line 1:
Command Line 2:
In fact, I added my own debugging, and the
.append()does not even trigger the__setitem__function of thePickleShareDBclass.Fix
Since the
__setitem__magic method only triggers when the value of a key is set, or updated, it does not trigger when you.append()something.Also, there is no magic method that triggers when an
.append()happensSo I suggest adding an
.append()function:Test
Command Line 1:
Command Line 2:
Command Line 1:
Command Line 2:
It would be nice if you could overwrite the default
.append()function, likedb['stack'].append(0)but since everydb['key']is not an instance of the class PickleShareDB but a list, I don't want to mess with it :D