Skip to content

Commit f44e8ce

Browse files
committed
feat!: remove add_observer() and short registry names (deprecated since v2.x)
- Remove `add_observer()` method (deprecated v2.3.2, use `add_listener()`) - Remove short name registration in registry (deprecated v0.8, use fully qualified names) - Update release notes and upgrade guide accordingly
1 parent fde13d9 commit f44e8ce

6 files changed

Lines changed: 4 additions & 52 deletions

File tree

docs/releases/3.0.0.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,9 @@ def on_validate(self, previous_configuration):
468468
```
469469

470470

471-
### `add_observer()` renamed to `add_listener()`
471+
### `add_observer()` removed
472472

473-
The method `add_observer` has been renamed to `add_listener`. The old name still works but emits
474-
a `DeprecationWarning`.
473+
The method `add_observer`, deprecated since v2.3.2, has been removed. Use `add_listener` instead.
475474

476475

477476
### `TransitionNotAllowed` exception changes

docs/releases/upgrade_2x_to_3.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ while not sm.is_terminated:
159159

160160
## Replace `add_observer()` with `add_listener()`
161161

162-
The method `add_observer` has been renamed to `add_listener`. The old name still works but emits
163-
a `DeprecationWarning`.
162+
The method `add_observer` has been removed in v3.0. Use `add_listener` instead.
164163

165164
**Before (2.x):**
166165

statemachine/registry.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
from .utils import qualname
42

53
try:
@@ -16,18 +14,11 @@ def autodiscover_modules(module_name: str):
1614

1715
def register(cls):
1816
_REGISTRY[qualname(cls)] = cls
19-
_REGISTRY[cls.__name__] = cls
2017
return cls
2118

2219

2320
def get_machine_cls(name):
2421
init_registry()
25-
if "." not in name:
26-
warnings.warn(
27-
"""Use fully qualified names (<module>.<class>) for state machine mixins.""",
28-
DeprecationWarning,
29-
stacklevel=2,
30-
)
3122
return _REGISTRY[name]
3223

3324

statemachine/statemachine.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,6 @@ def _register_callbacks(self, listeners: List[object]):
243243

244244
self._callbacks.async_or_sync()
245245

246-
def add_observer(self, *observers):
247-
"""Add a listener."""
248-
warnings.warn(
249-
"""Method `add_observer` has been renamed to `add_listener`.""",
250-
DeprecationWarning,
251-
stacklevel=2,
252-
)
253-
return self.add_listener(*observers)
254-
255246
def add_listener(self, *listeners):
256247
"""Add a listener.
257248

tests/test_listener.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from statemachine.state import State
32
from statemachine.statemachine import StateMachine
43

@@ -57,30 +56,6 @@ def on_enter_state(self, target, event):
5756
captured = capsys.readouterr()
5857
assert captured.out == EXPECTED_LOG_CREATION
5958

60-
def test_deprecated_api(self, campaign_machine, capsys):
61-
class LogObserver:
62-
def __init__(self, name):
63-
self.name = name
64-
65-
def on_transition(self, event, state, target):
66-
print(f"{self.name} on: {state.id}--({event})-->{target.id}")
67-
68-
def on_enter_state(self, target, event):
69-
print(f"{self.name} enter: {target.id} from {event}")
70-
71-
sm = campaign_machine()
72-
73-
with pytest.warns(
74-
DeprecationWarning, match="Method `add_observer` has been renamed to `add_listener`."
75-
):
76-
sm.add_observer(LogObserver("Frodo"))
77-
78-
sm.add_job()
79-
sm.produce()
80-
81-
captured = capsys.readouterr()
82-
assert captured.out == EXPECTED_LOG_ADD
83-
8459

8560
def test_regression_456():
8661
class TestListener:

tests/test_registry.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ class CampaignMachine(StateMachine):
2525
add_job = draft.to(draft) | producing.to(producing)
2626
produce = draft.to(producing)
2727

28-
assert "CampaignMachine" in registry._REGISTRY
2928
assert registry.get_machine_cls("tests.test_registry.CampaignMachine") == CampaignMachine
30-
31-
with pytest.warns(DeprecationWarning, match="fully qualified names"):
32-
assert registry.get_machine_cls("CampaignMachine") == CampaignMachine
29+
assert "CampaignMachine" not in registry._REGISTRY
3330

3431

3532
def test_load_modules_should_call_autodiscover_modules(django_autodiscover_modules):

0 commit comments

Comments
 (0)