A system I'm developing allows external users to develop plugins, which are basically subclasses of a predefined interface. An initialise()
function is called which receives an argument called data
from class Data
. I would like to forbid the external users, who implement the subclass method initialise(self, data)
, to make any changes to data
. I want it to be a readonly argument.
The object data
contains a lot of preloaded data, including possibly large dataframes. Passing a duplicate of the original argument data
is thus undesirable. On the other hand, it is safe, as if the user changes anything in the copy it will not affect the original.
Another option is to obfuscate the original attributes using @property
and forbidding any changes with @atribute.setter
. The Data
class has many attributes (around 40). It is possible, but the user can still make a mess in case they really try, and the class code will have MANY @property
decorators, one per attribute. Still, it is so far my preferred solution.
Is there any other possible, perhaps more elegant, or more private, solution to this problem?