Skip to content

Commit

Permalink
Compute _config parameters once
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 12, 2023
1 parent fab0490 commit 02d6795
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,8 @@ class _config(_base_config):
_session_config = WeakKeyDictionary()

def __init__(self, **params):
self._parameter_set = set()
super().__init__(**params)
self._validating = False
self._parameter_set = set(self.param)
for p in self._parameter_set:
if p.startswith('_') and p[1:] not in _config._globals:
setattr(self, p+'_', None)
Expand Down Expand Up @@ -372,7 +370,7 @@ def _enable_notifications(self):
def set(self, **kwargs):
values = [(k, v) for k, v in self.param.values().items() if k != 'name']
overrides = [
(k, getattr(self, k+'_')) for k in self._parameter_set
(k, getattr(self, k+'_')) for k in _config._parameter_set
if k.startswith('_') and k[1:] not in _config._globals
]
for k, v in kwargs.items():
Expand All @@ -398,9 +396,9 @@ def __setattr__(self, attr, value):
if attr in _config._globals or self.param._TRIGGER:
super().__setattr__(attr if attr in self.param else f'_{attr}', value)
elif state.curdoc is not None:
if attr in self._parameter_set:
if attr in _config._parameter_set:
validate_config(self, attr, value)
elif f'_{attr}' in self._parameter_set:
elif f'_{attr}' in _config._parameter_set:
validate_config(self, f'_{attr}', value)
else:
raise AttributeError(f'{attr!r} is not a valid config parameter.')
Expand All @@ -410,7 +408,7 @@ def __setattr__(self, attr, value):
watchers = param_watchers(self).get(attr, {}).get('value', [])
for w in watchers:
w.fn()
elif f'_{attr}' in self._parameter_set and hasattr(self, f'_{attr}_'):
elif f'_{attr}' in _config._parameter_set and hasattr(self, f'_{attr}_'):
validate_config(self, f'_{attr}', value)
super().__setattr__(f'_{attr}_', value)
else:
Expand Down Expand Up @@ -449,7 +447,7 @@ def __getattribute__(self, attr):
return super().__getattribute__(attr)
elif curdoc and curdoc in session_config and attr in session_config[curdoc]:
return session_config[curdoc][attr]
elif f'_{attr}' in self._parameter_set and getattr(self, f'_{attr}_') is not None:
elif f'_{attr}' in _config._parameter_set and getattr(self, f'_{attr}_') is not None:
return super().__getattribute__(f'_{attr}_')
return super().__getattribute__(attr)

Expand Down Expand Up @@ -615,7 +613,7 @@ def theme(self):
_params = _config.param.objects()
else:
_params = _config.param.params()

_config._parameter_set = set(_params)
config = _config(**{k: None if p.allow_None else getattr(_config, k)
for k, p in _params.items() if k != 'name'})

Expand Down

0 comments on commit 02d6795

Please sign in to comment.