Added listener decorator documentation (#161)

* added decorator example to connection.rst

since decorators are more pythonic, it was put in front of the register method.

* Expanded listener decorator docstring

* changed autofunction to autodecorator

* removed whitespace in empty line

* remvoed trailing whitespace

i didn't even edit there WTF
This commit is contained in:
laundmo authored and GitHub committed 2020-08-17 17:49:25 +02:00
1 parent ff9a0813b6
commit 2947aa6619
2 files changed
+26 -2

No files matched your search

+5 -1
View File
@@ -105,7 +105,7 @@ class Connection(object):
""" # NOQA
# This lock is re-entrant because it may be acquired in a re-entrant
# manner from within an outgoing packet listener
# manner from within an outgoing packet
self._write_lock = RLock()
self.networking_thread = None
@@ -195,6 +195,10 @@ class Connection(object):
def listener(self, *packet_types, **kwds):
"""
Shorthand decorator to register a function as a packet listener.
Wraps :meth:`minecraft.networking.connection.register_packet_listener`
:param packet_types: Packet types to listen for.
:param kwds: Keyword arguments for `register_packet_listener`
"""
def listener_decorator(handler_func):
self.register_packet_listener(handler_func, *packet_types, **kwds)