Skip to content

Commit 93fa2ba

Browse files
committed
refactor: no error if an unsubscription function is called multiple times
1 parent 35672e0 commit 93fa2ba

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Version 0.9.24
4+
5+
- refactor: no error if an unsubscription function is called multiple times
6+
37
## Version 0.9.23
48

59
- feat(combine_reducers): initialization of sub-reducers is done with `CombineReducerInitAction`

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-redux"
3-
version = "0.9.23"
3+
version = "0.9.24"
44
description = "Redux implementation for Python"
55
authors = ["Sassan Haradji <sassanh@gmail.com>"]
66
license = "Apache-2.0"

redux/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def run() -> None:
105105
if isinstance(listener_, weakref.ref):
106106
listener = listener_()
107107
if listener is None:
108-
listeners.remove(listener_)
108+
listeners.discard(listener_)
109109
continue
110110
else:
111111
listener = listener_
@@ -117,7 +117,7 @@ def run() -> None:
117117
if isinstance(event_handler_, weakref.ref):
118118
event_handler = event_handler_()
119119
if event_handler is None:
120-
event_handlers[type(event)].remove(
120+
event_handlers[type(event)].discard(
121121
(event_handler_, options),
122122
)
123123
continue
@@ -182,7 +182,7 @@ def subscribe_event(
182182
event_handlers[cast(type[Event], event_type)].add(
183183
(handler_ref, subscription_options),
184184
)
185-
return lambda: event_handlers[cast(type[Event], event_type)].remove(
185+
return lambda: event_handlers[cast(type[Event], event_type)].discard(
186186
(handler_ref, subscription_options),
187187
)
188188

@@ -255,7 +255,7 @@ def check_and_call(state: State) -> None:
255255
if isinstance(subscriber_, weakref.ref):
256256
subscriber = subscriber_()
257257
if subscriber is None:
258-
subscriptions.remove(subscriber_)
258+
subscriptions.discard(subscriber_)
259259
continue
260260
else:
261261
subscriber = subscriber_
@@ -291,7 +291,7 @@ def subscribe(
291291
callback(self.value)
292292

293293
def unsubscribe() -> None:
294-
subscriptions.remove(callback_ref)
294+
subscriptions.discard(callback_ref)
295295

296296
return unsubscribe
297297

0 commit comments

Comments
 (0)