Now constructions like await lock # "yield from lock" can be used as well try: ... finally: lock.release() and with (yield from lock): ... are supported. Let's deprecate them in favor of async with lock: ...
This can make harder writing portable code that works in 2.7, 3.4 and 3.7. What is the benefit of the deprecation? Are there inevitable design or implementation errors in these constructions? Or getting rid of them can significantly simplify the implementation?
1. asyncio is not supported by 2.7 anyway 2. with (yield from lock) is based on very non-obvious tricks: a) lock.__enter__ is forbidden and raises RuntimeError b) actually lock.__iter__ is called for lock acquiring *before* calling `with` c) the object returned from __iter__ is a context manager with __enter__/__exit__ methods 3. asyncio is converted to async/await syntax by https://bugs.python.org/issue32193 (old `yield from` style is fully supported still). 4. the deprecation was proposed by Yury Selivanov in https://github.com/python/cpython/pull/4753#discussion_r155658200
> This can make harder writing portable code that works in 2.7, 3.4 and 3.7. asyncio for Python 3.4 is fairly outdated. Most of the async packages today require 3.5+, as they usually use async/await syntax. I say this sort of backwards compatibility (showing a warning) isn't really a big concern. A bigger concern for us is new code using 'with await lock' pattern, hence the warning.