Skip to content

Commit 28fa83e

Browse files
committed
[handlers] descriptive repr for Handler
1 parent 83225d4 commit 28fa83e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pywa/handlers.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111
... def print_text(wa, m):
1212
... print(m.text)
1313
14+
# Or when you don't have access yet to the WhatsApp instance
15+
16+
# my_handlers.py
17+
>>> @WhatsApp.on_callback_button(filters.text)
18+
... def print_text(wa, m):
19+
... print(m.text)
20+
# main.py
21+
>>> from . import my_handlers
22+
>>> wa = WhatsApp(handlers_modules=[my_handlers])
23+
# Or
24+
>>> wa.load_handlers_modules(my_handlers)
25+
26+
# Remove a callback
1427
>>> wa.remove_callbacks(print_text)
1528
1629
# Register a callback programmatically
@@ -187,6 +200,12 @@ def _fields_to_subclasses() -> dict[str, type[Handler]]:
187200
},
188201
)
189202

203+
def __repr__(self) -> str:
204+
return f"{self.__class__.__name__}(callback={self._callback}, filters={self._filters}, priority={self._priority})"
205+
206+
def __str__(self) -> str:
207+
return self.__repr__()
208+
190209

191210
class MessageHandler(Handler):
192211
"""
@@ -263,6 +282,9 @@ async def ahandle(self, wa: WhatsApp, update: _FactorySupported) -> bool:
263282
return False
264283
return await super().ahandle(wa, update)
265284

285+
def __repr__(self) -> str:
286+
return f"{self.__class__.__name__}(callback={self._callback}, filters={self._filters}, factory={self._factory}, priority={self._priority})"
287+
266288

267289
class CallbackButtonHandler(_FactoryHandler):
268290
"""

0 commit comments

Comments
 (0)