Drop support for Python 3.4 and make minimum version 3.5.2.

This commit is contained in:
Rapptz
2018-06-10 18:09:14 -04:00
parent 7eb918b19e
commit f25091efe1
35 changed files with 626 additions and 1069 deletions

View File

@ -93,17 +93,8 @@ to handle it, which defaults to print a traceback and ignoring 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 ``async def``
functions or in 3.4 decorated with :func:`asyncio.coroutine`.
The following two functions are examples of coroutine functions: ::
async def on_ready():
pass
@asyncio.coroutine
def on_ready():
pass
errors. In order to turn a function into a coroutine they must be ``async def``
functions.
.. function:: on_connect()
@ -1306,22 +1297,11 @@ Some API functions return an "async iterator". An async iterator is something th
capable of being used in an `async for <https://docs.python.org/3/reference/compound_stmts.html#the-async-for-statement>`_
statement.
These async iterators can be used as follows in 3.5 or higher: ::
These async iterators can be used as follows: ::
async for elem in channel.history():
# do stuff with elem here
If you are using 3.4 however, you will have to use the more verbose way: ::
iterator = channel.history() # or whatever returns an async iterator
while True:
try:
item = yield from iterator.next()
except discord.NoMoreItems:
break
# do stuff with item here
Certain utilities make working with async iterators easier, detailed below.
.. class:: AsyncIterator

View File

@ -15,27 +15,6 @@ Coroutines
Questions regarding coroutines and asyncio belong here.
I get a SyntaxError around the word ``async``\! What should I do?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This :exc:`SyntaxError` happens because you're using a Python version lower than 3.5. Python 3.4 uses ``@asyncio.coroutine`` and
``yield from`` instead of ``async def`` and ``await``.
Thus you must do the following instead: ::
async def foo():
await bar()
# into
@asyncio.coroutine
def foo():
yield from bar()
Don't forget to ``import asyncio`` on the top of your files.
**It is heavily recommended that you update to Python 3.5 or higher as it simplifies asyncio massively.**
What is a coroutine?
~~~~~~~~~~~~~~~~~~~~~~
@ -195,11 +174,6 @@ technically in another thread, we must take caution in calling thread-safe opera
us, :mod:`asyncio` comes with a :func:`asyncio.run_coroutine_threadsafe` function that allows us to call
a coroutine from another thread.
.. warning::
This function is only part of 3.5.1+ and 3.4.4+. If you are not using these Python versions then use
``discord.compat.run_coroutine_threadsafe``.
However, this function returns a :class:`concurrent.Future` and to actually call it we have to fetch its result. Putting all of
this together we can do the following: ::

View File

@ -11,9 +11,9 @@ in creating applications that utilise the Discord API.
Prerequisites
---------------
discord.py works with Python 3.4.2 or higher. Support for earlier versions of Python
is not provided. Python 2.7 or lower is not supported. Python 3.3 is not supported
due to one of the dependencies (``aiohttp``) not supporting Python 3.3.
discord.py works with Python 3.5.2 or higher. Support for earlier versions of Python
is not provided. Python 2.7 or lower is not supported. Python 3.4 or lower is not supported
due to one of the dependencies (``aiohttp``) not supporting Python 3.4.
.. _installing:

View File

@ -14,6 +14,13 @@ new library.
Part of the redesign involves making things more easy to use and natural. Things are done on the
:ref:`models <discord_api_models>` instead of requiring a :class:`Client` instance to do any work.
Python Version Change
-----------------------
In order to make development easier and also to allow for our dependencies to upgrade to allow usage of 3.7 or higher,
the library had to remove support for Python versions lower than 3.5.2, which essentially means that **support for Python 3.4
is dropped**.
Major Model Changes
---------------------
@ -441,14 +448,14 @@ Prior to v1.0, certain functions like ``Client.logs_from`` would return a differ
In v1.0, this change has been reverted and will now return a singular type meeting an abstract concept called
:class:`AsyncIterator`.
This allows you to iterate over it like normal in Python 3.5+: ::
This allows you to iterate over it like normal: ::
async for message in channel.history():
print(message)
Or turn it into a list for either Python 3.4 or 3.5+: ::
Or turn it into a list: ::
messages = await channel.history().flatten() # use yield from for 3.4!
messages = await channel.history().flatten()
for message in messages:
print(message)