Closed Vincouux closed 7 months ago
list
is a mutable data structure in Python. In your example, new instances of class A
reference and modify the same list object in memory. You can read more about this here.
The Record
class has quite simple logic for working with default
. As a solution, you could add a default_factory
implementation, like here. Or, do not use default
and instantiate objects of the Record
class by passing arguments manually.
I decided to remove default and making every mutable data structures required as a solution ! Thanks for the answer.
Version
OS: Ubuntu 22.04 Python: 3.10.2 Pulsar: pulsar-client==3.2.0
Minimal reproduce step
What did you expect to see?
I expected the A class not to re-use the previous reference to the list.
What did you see instead?
As a developer, instantiating a fresh object in Python generally means it's built from scratch. Therefore, no reference to previously built objects should be used.