Skip to content

Commit 4e772f4

Browse files
committed
no need to be clever - just inherit
1 parent 8e7fde2 commit 4e772f4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/py/reactpy/reactpy/_option.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
UNDEFINED = cast(Any, object())
1212

1313

14-
def deprecate(option: Option[_O], message: str) -> Option[_O]:
15-
option.__class__ = _DeprecatedOption
16-
option._deprecation_message = message
17-
return option
18-
19-
2014
class Option(Generic[_O]):
2115
"""An option that can be set using an environment variable of the same name"""
2216

@@ -138,7 +132,13 @@ def __repr__(self) -> str:
138132
return f"Option({self._name}={self.current!r})"
139133

140134

141-
class _DeprecatedOption(Option[_O]): # nocov
135+
class DeprecatedOption(Option[_O]):
136+
"""An option that will warn when it is accessed"""
137+
138+
def __init__(self, *args: Any, message: str, **kwargs: Any) -> None:
139+
super().__init__(*args, **kwargs)
140+
self._deprecation_message = message
141+
142142
@Option.current.getter # type: ignore
143143
def current(self) -> _O:
144144
warn(self._deprecation_message, DeprecationWarning)

src/py/reactpy/tests/test__option.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from reactpy._option import Option, deprecate
6+
from reactpy._option import DeprecatedOption, Option
77

88

99
def test_option_repr():
@@ -102,7 +102,7 @@ def test_option_subscribe():
102102

103103

104104
def test_deprecated_option():
105-
opt = deprecate(Option("A_FAKE_OPTION", None), "is deprecated!")
105+
opt = DeprecatedOption("A_FAKE_OPTION", None, message="is deprecated!")
106106

107107
with pytest.warns(DeprecationWarning, match="is deprecated!"):
108108
assert opt.current is None

0 commit comments

Comments
 (0)