Skip to content

Bypassing data between classes containing array elements #100558

@amaciasmedri

Description

@amaciasmedri

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions