Skip to content

Commit

Permalink
DeprecatedOption must mirror regular option
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Feb 3, 2022
1 parent e4fca65 commit c146dfb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
35 changes: 15 additions & 20 deletions src/idom/_option.py
Expand Up @@ -93,31 +93,26 @@ def __repr__(self) -> str:


class DeprecatedOption(Option[_O]): # pragma: no cover
def __init__(self, new_name: str | None, *args: Any, **kwargs: Any) -> None:
self.new_name = new_name
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
super().__init__(*args, **kwargs)
def __init__(self, new_opt: Option | None, name: str) -> None:
# copy over attrs
attrs = new_opt.__dict__.copy()
attrs.pop("_current", None)
self.__dict__.update(new_opt.__dict__)
# then set the ones needed here
self._name = name
self._new_opt = new_opt

@property
def current(self) -> _O:
if self.new_name is None:
def _current(self) -> _O:
if self._new_opt.name is None:
warnings.warn(f"{self.name!r} has been removed", DeprecationWarning)
else:
warnings.warn(
f"{self.name!r} has been renamed to {self.new_name!r}",
f"{self.name!r} has been renamed to {self._new_opt.name!r}",
DeprecationWarning,
)
return super().current
return self._new_opt.current

@current.setter
def current(self, new: _O) -> None:
if self.new_name is None:
warnings.warn(f"{self.name!r} has been removed", DeprecationWarning)
else:
warnings.warn(
f"{self.name!r} has been renamed to {self.new_name!r}",
DeprecationWarning,
)
self.set_current(new)
return None
@_current.setter
def _current(self, new: _O) -> None:
self._new_opt.current = new
14 changes: 6 additions & 8 deletions src/idom/config.py
Expand Up @@ -44,14 +44,6 @@
# Because these web modules will be linked dynamically at runtime this can be temporary
_DEFAULT_WEB_MODULES_DIR = TemporaryDirectory()

IDOM_WED_MODULES_DIR: _Option[Path] = _DeprecatedOption(
new_name="IDOM_WEB_MODULES_DIR",
name="IDOM_WED_MODULES_DIR",
default=Path(_DEFAULT_WEB_MODULES_DIR.name),
validator=Path,
)
"""This has been renamed to :data:`IDOM_WEB_MODULES_DIR`"""

IDOM_WEB_MODULES_DIR = _Option(
"IDOM_WEB_MODULES_DIR",
default=Path(_DEFAULT_WEB_MODULES_DIR.name),
Expand All @@ -64,6 +56,12 @@
set of publically available APIs for working with the client.
"""

IDOM_WED_MODULES_DIR: _Option[Path] = _DeprecatedOption(
new_opt=IDOM_WEB_MODULES_DIR,
name="IDOM_WED_MODULES_DIR",
)
"""This has been renamed to :data:`IDOM_WEB_MODULES_DIR`"""

IDOM_FEATURE_INDEX_AS_DEFAULT_KEY = _Option(
"IDOM_FEATURE_INDEX_AS_DEFAULT_KEY",
default=True,
Expand Down

0 comments on commit c146dfb

Please sign in to comment.