Skip to content

Commit

Permalink
user-APIs: forbid setting non-existing attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Nov 27, 2023
1 parent c788287 commit 40bdd62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^

Expand Down
4 changes: 3 additions & 1 deletion jdaviz/core/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 40bdd62

Please sign in to comment.