Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Breaking API Change in Python 3.13.3: Task Factory Signature Change #133745

Closed
1 of 1 issue completed
Closed
Assignees
Yhg1skumaraditya303
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesrelease-blockerstdlibPython modules in the Lib dirtopic-asynciotype-bugAn unexpected behavior, bug, or error
@pablogsal

Description

@pablogsal

In PR#128768 (gh-128308), the asyncio task factory signature was changed from(loop, coro, context=None) to(loop, coro, **kwargs). This seemingly minor change breaks backward compatibility for existing task factory implementations.

The documentation was updated to reflect this new contract:

  • Old:(loop, coro, context=None), where the callable must return aasyncio.Future-compatible object.
  • New:(loop, coro, **kwargs), where the callable must pass on all *kwargs, and return aasyncio.Task-compatible object.

This change causes runtime errors for any code with task factories implemented according to the previous contract, as these factories now unexpectedly receive keyword arguments likename that they aren't designed to handle.

Reproducer

importasyncio# Task factory implemented according to the previous API contractdefold_style_task_factory(loop,coro,context=None):print(f"Creating task with loop={loop}, coro={coro}, context={context}")returnasyncio.Task(coro,loop=loop)asyncdefmain():# Set up a custom task factory following the old documented APIloop=asyncio.get_event_loop()loop.set_task_factory(old_style_task_factory)# This will fail with TypeError due to unexpected 'name' argumentprint("Attempting to create task with name...")awaitloop.create_task(asyncio.sleep(0.1),name="test_task")print("Task completed successfully")# We won't reach this lineif__name__=="__main__":try:asyncio.run(main())exceptTypeErrorase:print(f"ERROR:{e}")# Output: ERROR: old_style_task_factory() got an unexpected keyword argument 'name'

This prints:

Attempting to create task with name...Creating task with loop=<_UnixSelectorEventLoop running=False closed=False debug=False>, coro=<coroutine object BaseEventLoop.shutdown_asyncgens at 0x72b413aa5450>, context=NoneCreating task with loop=<_UnixSelectorEventLoop running=False closed=False debug=False>, coro=<coroutine object BaseEventLoop.shutdown_default_executor at 0x72b413cc5910>, context=NoneERROR: old_style_task_factory() got an unexpected keyword argument 'name'<sys>:0: RuntimeWarning: coroutine 'sleep' was never awaitedRuntimeWarning: Enable tracemalloc to get the object allocation traceback

This is a breaking change introduced in a patch release, which violates our versioning policy. The change was intended to support thename keyword argument for eager tasks, but the implementation method has unintentionally broken existing code that followed the previously documented API contract.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Sub-issues

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesrelease-blockerstdlibPython modules in the Lib dirtopic-asynciotype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp