class documentation

resembling somewhat types.SimpleNamespace from Python >=3.3 but with instantiation and resembling even more the dataclass decorator from Python >=3.7.

MyClassSettings(DefaultSettings) is preferably used by assigning a settings attribute in __init__ like:

>>> class MyClass:
...     def __init__(self, a, b=None, param1=None, c=3):
...         self.settings = MyClassSettings(locals(), 1, self)

The 1 signals, purely for consistency checking, that one parameter defined in MyClassSettings is to be set from locals(). MyClassSettings doesn't use any names which are already defined in self.__dict__. The settings are defined in a derived parameter class like

>>> from cma.fitness_models import DefaultSettings
>>> class MyClassSettings(DefaultSettings):
...     param1 = 123
...     val2 = False
...     another_par = None  # we need to assign at least None always

The main purpose is, with the least effort, (i) to separate parameters/settings of a class from its remaining attributes, and (ii) to be flexible as to which of these parameters are arguments to __init__. Parameters can always be modified after instantiation. Further advantages are (a) no typing of self. to assign the default value or the passed parameter value (the latter are assigned "automatically") and (b) no confusing name change between the passed option and attribute name is possible.

The class does not allow to overwrite the default value with None.

Now any of these parameters can be used or re-assigned like

>>> c = MyClass(0.1)
>>> c.settings.param1 == 123
True
>>> c = MyClass(2, param1=False)
>>> c.settings.param1 is False
True
Method __init__ Overwrite default settings in case.
Method __str__ Undocumented
Instance Variable inparams Undocumented
Instance Variable obj Undocumented
Method _set_from_defaults defaults are taken from the class attributes
Method _set_from_input Only existing parameters/attributes and non-None values are set.
Instance Variable _number_of_params Undocumented
def __init__(self, params, number_of_params, obj):

Overwrite default settings in case.

Parameters
paramsA dictionary (usually locals()) containing the parameters to set/overwrite
number_of_paramsNumber of parameters to set/overwrite
objelements of obj.__dict__ are in the ignore list.
def __str__(self):

Undocumented

inparams =

Undocumented

obj =

Undocumented

def _set_from_defaults(self):

defaults are taken from the class attributes

def _set_from_input(self):

Only existing parameters/attributes and non-None values are set.

The number of parameters is cross-checked.

Remark: we could select only the last arguments of obj.__init__.__func__.__code__.co_varnames which have defaults obj.__init__.__func__.__defaults__ (we do not need the defaults)

_number_of_params =

Undocumented