From 40bdd629610294c92a92a278b323bfdd169fb978 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Mon, 27 Nov 2023 13:51:28 -0500 Subject: [PATCH] user-APIs: forbid setting non-existing attribute --- CHANGES.rst | 3 +++ jdaviz/core/user_api.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index dde4d30967..1243d2b2ad 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -53,6 +53,9 @@ Specviz2d API Changes ----------- +- User APIs now raise a warning when attempting to set a non-existing attribute to avoid confusion + caused by typos, etc. [#2577] + Cubeviz ^^^^^^^ diff --git a/jdaviz/core/user_api.py b/jdaviz/core/user_api.py index b8cd6341ad..6b6d124e96 100644 --- a/jdaviz/core/user_api.py +++ b/jdaviz/core/user_api.py @@ -34,8 +34,10 @@ def __getattr__(self, attr): return getattr(exp_obj, 'user_api', exp_obj) def __setattr__(self, attr, value): - if attr in _internal_attrs or attr not in self._expose: + if attr in _internal_attrs: return super().__setattr__(attr, value) + if attr not in self._expose: + raise ValueError(f"{attr} is not a valid attribute and cannot be set") if attr in self._readonly: raise AttributeError("cannot set read-only item")