From 80fa60ec85c53d95893a5a05c73a495fa6ca184a Mon Sep 17 00:00:00 2001 From: goov Date: Wed, 24 Mar 2021 15:14:27 +0500 Subject: [PATCH 1/3] fix bug with using deprecated method for python 3.9 ---- asyncio.Task.current_task method is deprecated and will be removed in Python 3.9. Use the asyncio.current_task() function instead --- setup.py | 2 ++ src/aiocontext/context.py | 7 ++++++- src/aiocontext/task_factory.py | 8 ++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 2f3625b..8eec8ac 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,8 @@ 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python', 'Topic :: Software Development', diff --git a/src/aiocontext/context.py b/src/aiocontext/context.py index a02299d..9b1b34b 100644 --- a/src/aiocontext/context.py +++ b/src/aiocontext/context.py @@ -1,6 +1,7 @@ """Context information storage for asyncio.""" import asyncio +import sys from collections import ChainMap from collections.abc import MutableMapping from contextlib import suppress @@ -70,7 +71,11 @@ def get_data(self, task=None): {'key': 'value'} """ if task is None: - task = asyncio.Task.current_task() + if sys.version_info < (3, 9): + task = asyncio.Task.current_task() + else: + task = asyncio.current_task() + if task is None: raise EventLoopError("No event loop found") data = getattr(task, self._data_attr, None) diff --git a/src/aiocontext/task_factory.py b/src/aiocontext/task_factory.py index d89ca77..e209cd9 100644 --- a/src/aiocontext/task_factory.py +++ b/src/aiocontext/task_factory.py @@ -1,12 +1,12 @@ """Task factory.""" import asyncio +import sys from functools import wraps from .__about__ import __title__ from .errors import TaskFactoryError - _TASK_FACTORY_ATTR = '_{}_contexts'.format(__title__) @@ -56,7 +56,11 @@ def custom_task_factory(loop, coro): @wraps(task_factory) def wrapper(loop, coro): - parent_task = asyncio.Task.current_task(loop=loop) + if sys.version_info < (3, 9): + parent_task = asyncio.Task.current_task(loop=loop) + else: + parent_task = asyncio.current_task(loop=loop) + child_task = task_factory(loop, coro) if child_task._source_traceback: del child_task._source_traceback[-1] From 520c7db27234d4a214eae6b5e976f2c97a6f738d Mon Sep 17 00:00:00 2001 From: goov Date: Wed, 24 Mar 2021 15:37:23 +0500 Subject: [PATCH 2/3] add 3.9 to tox configs --- .travis.yml | 5 +++++ tox.ini | 2 ++ 2 files changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4f77e75..ba18029 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,11 @@ matrix: after_success: - coverage combine - codecov + - python: "3.9" + env: TOXENV=py39-cov + after_success: + - coverage combine + - codecov - env: TOXENV=manifest - env: TOXENV=metadata - env: TOXENV=doc8 diff --git a/tox.ini b/tox.ini index 12e0969..9543c7f 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,8 @@ envlist = py35 py36 py37 + py38 + py39 manifest metadata doc8 From e9e47b07c5a95873bda7e109503616902dffb2db Mon Sep 17 00:00:00 2001 From: goov Date: Wed, 24 Mar 2021 15:52:48 +0500 Subject: [PATCH 3/3] fix envs --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ba18029..16879c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,12 +15,12 @@ matrix: - python: "3.5" env: TOXENV=py35 - python: "3.6" - env: TOXENV=py36-cov + env: TOXENV=py36 after_success: - coverage combine - codecov - python: "3.9" - env: TOXENV=py39-cov + env: TOXENV=py39 after_success: - coverage combine - codecov