In Python 3 everything is supposed to be an object, even numbers, but they're immutable.
Is it possible to create wrapper object for numbers, e.g. float, such that it would behave exactly as ordinary numbers except it must be mutable?
I've wondered whether it would be feasible using built-in type function by creating anonymous wrapper object deriving from float, but changing it behaviour to be mutable.
>>> f = lambda x : type('', (float,), dict())(x)
>>> a = f(9)
>>> a
9.0
What parameters must I change f to make number a be mutable?
How I verify if a number is mutable:
I must be able to create such function f that would create from integer value a float value and after shallow copy it would behave in the following manner:
>>> list_1 = [f(i) for i in [1, 2, 3, 4]]
>>> list_1
[1.0, 2.0, 3.0, 4.0]
>>> list_2 = copy.copy(list_1)
>>> list_1[0] *= 100
>>> list_1
[100.0, 2.0, 3.0, 4.0]
>>> list_2
[100.0, 2.0, 3.0, 4.0]
Modification of the first list, have changed both of them.
Maybe I must add some fields to dict() or add additional base class that would enforce mutability?