Is this a Bug? or does exist any documentation about it?
The following code was implemented on an Arch Linux distribution and Python v3.10.
class Array:
def __init__(self, A: list = []):
self.A: list = A
Temp = Array()
Temp.A.append(123)
BUG = Array()
print(BUG.A) # Output: [123]
BUG.A[0] = -654
print(Temp.A) # Output: [-654]
From my point of view, the pointer of element A was copied from Temp to BUG when the __init__ method was executed.
The initialization process with the default value A=[] in the constructor was omitted for the BUG object, instead, it was copied the previous pointer catched by the constructor. Some privileges between objects could be bypassed with this drawback.
#bypassing #class #array
Is this a Bug? or does exist any documentation about it?
The following code was implemented on an Arch Linux distribution and Python v3.10.
From my point of view, the pointer of element
Awas copied fromTemptoBUGwhen the__init__method was executed.The initialization process with the default value
A=[]in the constructor was omitted for theBUGobject, instead, it was copied the previous pointer catched by the constructor. Some privileges between objects could be bypassed with this drawback.#bypassing #class #array