Skip to content

bpo-34793: Drop old-style context managers in asyncio.locks#17533

Merged
asvetlov merged 3 commits intopython:masterfrom
asvetlov:drop-deprecations
Feb 1, 2020
Merged

bpo-34793: Drop old-style context managers in asyncio.locks#17533
asvetlov merged 3 commits intopython:masterfrom
asvetlov:drop-deprecations

Conversation

@asvetlov
Copy link
Copy Markdown
Contributor

@asvetlov asvetlov commented Dec 9, 2019

Comment thread Doc/whatsnew/3.9.rst
* ``with (await asyncio.lock):`` and ``with (yield from asyncio.lock):`` statements are
not longer supported, use ``async with lock`` instead. The same is correct for
``asyncio.Condition`` and ``asyncio.Semaphore``.
(Contributed by Andrew Svetlov in :issue:`34793`.)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also replace the deprecation warning with changedversion in https://docs.python.org/3/library/asyncio-sync.html#boundedsemaphore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread Lib/asyncio/locks.py
class _ContextManagerMixin:
def __enter__(self):
raise RuntimeError(
'"yield from" should be used as context manager expression')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this? We can change the error message to say that async with should be used...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the motivation was emphasizing that context managers were supported but in a slightly unusual way: with (yield from lock):; bare with lock: was forbidden.

After switching to async with lock: everything becomes clear: with is not supported in any form for the sake of async with. The error message is standard and well-known: AttributeError: __enter__. I think we shouldn't replace the default behavior.

Maybe the standard text can be improved globally, but it is another story, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants