Skip to content

Commit

Permalink
Copy explicit_no_refs from ClassPrivate to InstancePrivate (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Oct 24, 2023
1 parent 31f71c3 commit 0c5a92d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,9 @@ def __set__(self, obj, val):
else:
# When setting a Parameter before calling super.
if not isinstance(obj._param__private, _InstancePrivate):
obj._param__private = _InstancePrivate()
obj._param__private = _InstancePrivate(
explicit_no_refs=type(obj)._param__private.explicit_no_refs
)
_old = obj._param__private.values.get(name, self.default)
obj._param__private.values[name] = val
self._post_setter(obj, val)
Expand Down Expand Up @@ -4040,6 +4042,7 @@ class _InstancePrivate:
'syncing',
'watchers',
'values',
'explicit_no_refs',
]

def __init__(
Expand All @@ -4051,8 +4054,10 @@ def __init__(
params=None,
watchers=None,
values=None,
explicit_no_refs=None
):
self.initialized = initialized
self.explicit_no_refs = [] if explicit_no_refs is None else explicit_no_refs
self.syncing = set()
if parameters_state is None:
parameters_state = {
Expand Down Expand Up @@ -4132,7 +4137,9 @@ def __init__(self, **params):
# _InstancePrivate namespace over the _ClassPrivate namespace
# (see Parameter.__set__) so we shouldn't override it here.
if not isinstance(self._param__private, _InstancePrivate):
self._param__private = _InstancePrivate()
self._param__private = _InstancePrivate(
explicit_no_refs=type(self)._param__private.explicit_no_refs
)

# Skip generating a custom instance name when a class in the hierarchy
# has overriden the default of the `name` Parameter.
Expand Down Expand Up @@ -4191,12 +4198,13 @@ def __setstate__(self, state):
During this process the object is considered uninitialized.
"""
self._param__private = _InstancePrivate()
explicit_no_refs = type(self)._param__private.explicit_no_refs
self._param__private = _InstancePrivate(explicit_no_refs=explicit_no_refs)
self._param__private.initialized = False

_param__private = state.get('_param__private', None)
if _param__private is None:
_param__private = _InstancePrivate()
_param__private = _InstancePrivate(explicit_no_refs=explicit_no_refs)

# When making a copy the internal watchers have to be
# recreated and point to the new instance
Expand Down

0 comments on commit 0c5a92d

Please sign in to comment.