Skip to content

Commit c146dfb

Browse files
committed
DeprecatedOption must mirror regular option
1 parent e4fca65 commit c146dfb

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

src/idom/_option.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,31 +93,26 @@ def __repr__(self) -> str:
9393

9494

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

102105
@property
103-
def current(self) -> _O:
104-
if self.new_name is None:
106+
def _current(self) -> _O:
107+
if self._new_opt.name is None:
105108
warnings.warn(f"{self.name!r} has been removed", DeprecationWarning)
106109
else:
107110
warnings.warn(
108-
f"{self.name!r} has been renamed to {self.new_name!r}",
111+
f"{self.name!r} has been renamed to {self._new_opt.name!r}",
109112
DeprecationWarning,
110113
)
111-
return super().current
114+
return self._new_opt.current
112115

113-
@current.setter
114-
def current(self, new: _O) -> None:
115-
if self.new_name is None:
116-
warnings.warn(f"{self.name!r} has been removed", DeprecationWarning)
117-
else:
118-
warnings.warn(
119-
f"{self.name!r} has been renamed to {self.new_name!r}",
120-
DeprecationWarning,
121-
)
122-
self.set_current(new)
123-
return None
116+
@_current.setter
117+
def _current(self, new: _O) -> None:
118+
self._new_opt.current = new

src/idom/config.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@
4444
# Because these web modules will be linked dynamically at runtime this can be temporary
4545
_DEFAULT_WEB_MODULES_DIR = TemporaryDirectory()
4646

47-
IDOM_WED_MODULES_DIR: _Option[Path] = _DeprecatedOption(
48-
new_name="IDOM_WEB_MODULES_DIR",
49-
name="IDOM_WED_MODULES_DIR",
50-
default=Path(_DEFAULT_WEB_MODULES_DIR.name),
51-
validator=Path,
52-
)
53-
"""This has been renamed to :data:`IDOM_WEB_MODULES_DIR`"""
54-
5547
IDOM_WEB_MODULES_DIR = _Option(
5648
"IDOM_WEB_MODULES_DIR",
5749
default=Path(_DEFAULT_WEB_MODULES_DIR.name),
@@ -64,6 +56,12 @@
6456
set of publically available APIs for working with the client.
6557
"""
6658

59+
IDOM_WED_MODULES_DIR: _Option[Path] = _DeprecatedOption(
60+
new_opt=IDOM_WEB_MODULES_DIR,
61+
name="IDOM_WED_MODULES_DIR",
62+
)
63+
"""This has been renamed to :data:`IDOM_WEB_MODULES_DIR`"""
64+
6765
IDOM_FEATURE_INDEX_AS_DEFAULT_KEY = _Option(
6866
"IDOM_FEATURE_INDEX_AS_DEFAULT_KEY",
6967
default=True,

0 commit comments

Comments
 (0)