diff options
| author | Rapptz <[email protected]> | 2015-12-04 00:16:34 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-12-04 00:16:34 -0500 |
| commit | f197c345832ff09fe081b7cb542de9288d0b780e (patch) | |
| tree | 868d84f0708f9ceb9d3395bfd0223ef3c59a2514 /docs | |
| parent | Point to the docs in the README and clear up notes on breaking changes (diff) | |
| download | discord.py-f197c345832ff09fe081b7cb542de9288d0b780e.tar.xz discord.py-f197c345832ff09fe081b7cb542de9288d0b780e.zip | |
Begin working on asyncio port.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api.rst | 21 | ||||
| -rw-r--r-- | docs/conf.py | 7 |
2 files changed, 26 insertions, 2 deletions
diff --git a/docs/api.rst b/docs/api.rst index 935f05dc..1e0bdd62 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -34,17 +34,34 @@ overriding the specific events. For example: :: import discord class MyClient(discord.Client): + + @asyncio.coroutine def on_message(self, message): - self.send_message(message.channel, 'Hello World!') + yield from self.send_message(message.channel, 'Hello World!') If an event handler raises an exception, :func:`on_error` will be called to handle it, which defaults to print a traceback and ignore the exception. +.. warning:: + + All the events must be a |corourl|_. If they aren't, then you might get unexpected + errors. In order to turn a function into a coroutine they must either be decorated + with ``@asyncio.coroutine`` or in Python 3.5+ be defined using the ``async def`` + declaration. + + The following two functions are examples of coroutine functions: :: + + async def on_ready(): + pass + + @asyncio.coroutine + def on_ready(): + pass + .. versionadded:: 0.7.0 Subclassing to listen to events. - .. function:: on_ready() Called when the client is done preparing the data received from Discord. Usually after login is successful diff --git a/docs/conf.py b/docs/conf.py index 3183d776..bb5d585c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,12 +32,19 @@ sys.path.insert(0, os.path.abspath('..')) extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.extlinks', + 'sphinx.ext.napoleon', ] extlinks = { 'issue': ('https://github.com/Rapptz/discord.py/issues/%s', 'issue '), } +rst_prolog = """ +.. |coro| replace:: This function is a |corourl|_. +.. |corourl| replace:: *coroutine* +.. _corourl: https://docs.python.org/3/library/asyncio-task.html#coroutine +""" + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] |