Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 3.11 #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
12 changes: 6 additions & 6 deletions aiotask_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def chainmap_context_factory(parent_context=None):
return parent_context.new_child()


def task_factory(loop, coro, copy_context=False, context_factory=None):
def task_factory(loop, coro, context=None, copy_context=False, context_factory=None):
"""
By default returns a task factory that uses a simple dict as the task context,
but allows context creation and inheritance to be customized via ``context_factory``.
"""
context_factory = context_factory or partial(
dict_context_factory, copy_context=copy_context)

task = asyncio.tasks.Task(coro, loop=loop)
task = asyncio.tasks.Task(coro, loop=loop, context=context)
if task._source_traceback:
del task._source_traceback[-1]

Expand All @@ -77,7 +77,7 @@ def task_factory(loop, coro, copy_context=False, context_factory=None):
return task


def copying_task_factory(loop, coro):
def copying_task_factory(loop, coro, context=None):
"""
Returns a task factory that copies a task's context into new tasks instead of
sharing it.
Expand All @@ -86,18 +86,18 @@ def copying_task_factory(loop, coro):
:param coro: A coroutine object
:return: A context-copying task factory
"""
return task_factory(loop, coro, copy_context=True)
return task_factory(loop, coro, context=context, copy_context=True)


def chainmap_task_factory(loop, coro):
def chainmap_task_factory(loop, coro, context=None):
"""
Returns a task factory that uses ``ChainMap`` as the context.

:param loop: The active event loop
:param coro: A coroutine object
:return: A ``ChainMap`` task factory
"""
return task_factory(loop, coro, context_factory=chainmap_context_factory)
return task_factory(loop, coro, context=context, context_factory=chainmap_context_factory)


def get(key, default=None):
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="aiotask_context",
version="0.6.1",
version="0.6.2",
author="Manuel Miranda",
author_email="[email protected]",
description="Store context information inside the asyncio.Task object",
Expand All @@ -14,6 +14,10 @@
"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 :: 3.10",
"Programming Language :: Python :: 3.11",
],
packages=['aiotask_context'],
install_requires=install_requires,
Expand Down