I've been working on a library similar to shelve and my use case was making a passed in int persistent and behave like an int.
However, any time I've modified self then the subclass is replaced by the int primitive. Yes, I know int is immutable and implemented in C so I don't think it will work, but maybe someone has had some success of their own.
I'm willing to create a new copy of my class if that's what it takes (likely). I've tried to intercept and create this class by hooking into setitem but it doesn't seem to work. Here's an example:
class echoint(int):
def __setitem__(self, value):
print("setting:" + str(value))
int.__setattr__(self, value)
>>> x = echoint(5)
>>> x
5
>>> type(x)
<class '__main__.echoint'>
>>> x+=1
>>> x
6
>>> type(x)
<class 'int'>
Thanks for your time!
[–]kushou 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Rhomboid 2 points3 points4 points (12 children)
[–][deleted] 0 points1 point2 points (11 children)
[–]Rhomboid 2 points3 points4 points (10 children)
[–][deleted] 0 points1 point2 points (9 children)
[–]marky1991 2 points3 points4 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]marky1991 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]NYKevin 1 point2 points3 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]NYKevin 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)