Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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
after_success:
- coverage combine
- codecov
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion src/aiocontext/context.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/aiocontext/task_factory.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ envlist =
py35
py36
py37
py38
py39
manifest
metadata
doc8
Expand Down