Skip to content

Commit

Permalink
Dropped Python 3.7 support
Browse files Browse the repository at this point in the history
Includes mypy error fix.
  • Loading branch information
felixxm authored Oct 12, 2023
1 parent 56cc620 commit 09ed8e9
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 54 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- 3.7
- 3.8
- 3.9
- '3.10'
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ repos:
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
args: ["--py38-plus"]

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args: ["--target-version=py37"]
args: ["--target-version=py38"]

- repo: https://github.com/pycqa/isort
rev: 5.11.5
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ file handles for incoming POST bodies).
Dependencies
------------

``asgiref`` requires Python 3.7 or higher.
``asgiref`` requires Python 3.8 or higher.


Contributing
Expand Down
4 changes: 2 additions & 2 deletions asgiref/current_thread_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def _submit(

# Python 3.9+ has a new signature for submit with a "/" after `fn`, to enforce
# it to be a positional argument. If we ignore[override] mypy on 3.9+ will be
# happy but 3.7/3.8 will say that the ignore comment is unused, even when
# happy but 3.8 will say that the ignore comment is unused, even when
# defining them differently based on sys.version_info.
# We should be able to remove this when we drop support for 3.7/3.8.
# We should be able to remove this when we drop support for 3.8.
if not TYPE_CHECKING:

def submit(self, fn, *args, **kwargs):
Expand Down
31 changes: 6 additions & 25 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def _restore_context(context: contextvars.Context) -> None:
# inspect.iscoroutinefunction(), whilst also removing the _is_coroutine marker.
# The latter is replaced with the inspect.markcoroutinefunction decorator.
# Until 3.12 is the minimum supported Python version, provide a shim.
# Django 4.0 only supports 3.8+, so don't concern with the _or_partial backport.

if hasattr(inspect, "markcoroutinefunction"):
iscoroutinefunction = inspect.iscoroutinefunction
Expand All @@ -70,31 +69,15 @@ def markcoroutinefunction(func: _F) -> _F:
return func


if sys.version_info >= (3, 8):
_iscoroutinefunction_or_partial = iscoroutinefunction
else:

def _iscoroutinefunction_or_partial(func: Any) -> bool:
# Python < 3.8 does not correctly determine partially wrapped
# coroutine functions are coroutine functions, hence the need for
# this to exist. Code taken from CPython.
while inspect.ismethod(func):
func = func.__func__
while isinstance(func, functools.partial):
func = func.func

return iscoroutinefunction(func)


class ThreadSensitiveContext:
"""Async context manager to manage context for thread sensitive mode
This context manager controls which thread pool executor is used when in
thread sensitive mode. By default, a single thread pool executor is shared
within a process.
In Python 3.7+, the ThreadSensitiveContext() context manager may be used to
specify a thread pool per context.
The ThreadSensitiveContext() context manager may be used to specify a
thread pool per context.
This context manager is re-entrant, so only the outer-most call to
ThreadSensitiveContext will set the context.
Expand Down Expand Up @@ -157,10 +140,8 @@ def __init__(
force_new_loop: bool = False,
):
if not callable(awaitable) or (
not _iscoroutinefunction_or_partial(awaitable)
and not _iscoroutinefunction_or_partial(
getattr(awaitable, "__call__", awaitable)
)
not iscoroutinefunction(awaitable)
and not iscoroutinefunction(getattr(awaitable, "__call__", awaitable))
):
# Python does not have very reliable detection of async functions
# (lots of false negatives) so this is just a warning.
Expand Down Expand Up @@ -400,8 +381,8 @@ def __init__(
) -> None:
if (
not callable(func)
or _iscoroutinefunction_or_partial(func)
or _iscoroutinefunction_or_partial(getattr(func, "__call__", func))
or iscoroutinefunction(func)
or iscoroutinefunction(getattr(func, "__call__", func))
):
raise TypeError("sync_to_async can only be applied to sync functions.")
self.func = func
Expand Down
8 changes: 3 additions & 5 deletions asgiref/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
Callable,
Dict,
Iterable,
Literal,
Optional,
Protocol,
Tuple,
Type,
TypedDict,
Union,
)

if sys.version_info >= (3, 8):
from typing import Literal, Protocol, TypedDict
else:
from typing_extensions import Literal, Protocol, TypedDict

if sys.version_info >= (3, 11):
from typing import NotRequired
else:
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -28,7 +27,7 @@ project_urls =
Changelog = https://github.com/django/asgiref/blob/master/CHANGELOG.txt

[options]
python_requires = >=3.7
python_requires = >=3.8
packages = find:
include_package_data = true
install_requires =
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from setuptools import setup # type: ignore[import]
from setuptools import setup # type: ignore[import-untyped]

setup()
14 changes: 0 additions & 14 deletions specs/asgi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,6 @@ Note that messages received by a server after the connection has been
closed are not considered errors. In this case the ``send`` awaitable
callable should act as a no-op.


Extra Coroutines
----------------

Frameworks or applications may want to run extra coroutines in addition to the
coroutine launched for each application instance. Since there is no way to
parent these to the instance's coroutine in Python 3.7, applications should
ensure that all coroutines launched as part of running an application are terminated
either before or at the same time as the application's coroutine.

Any coroutines that continue to run outside of this window have no guarantees
about their lifetime and may be killed at any time.


Extensions
----------

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38,39,310,311}-{test,mypy}
py{38,39,310,311}-{test,mypy}
qa

[testenv]
Expand Down

0 comments on commit 09ed8e9

Please sign in to comment.