Yury Selivanov <yseliva...@gmail.com> added the comment:

Actually, I don't think we need a deprecation period.  Both methods are 
completely unusable now.

Given:

  async def foo():
    await asyncio.sleep(1)
    print('AAAAA')
    return 42


1. Let's try to use Task.set_result():

  async def main():
    f = asyncio.create_task(foo())
    f.set_result(123)
    result = await f
    print(result)

  asyncio.run(main())

This will print "123", but will give us an "AssertionError: _step(): already 
done: <Task finished coro=<foo() running at t.py:4> result=123> None" logged.


2. Let's try set_result + a sleep:

  async def main():
    f = asyncio.create_task(foo())
    await asyncio.sleep(2)
    f.set_result(123)
    result = await f
    print(result)


  asyncio.run(main())

This just crashes with an InvalidStateError.

3. Same happens with set_exception().


All in all, deprecation periods are useful when there's some working and useful 
functionality that has to be removed in the future.  In this case there's no 
working and no useful functionality.

So let's just make Task.set_result() and Task.set_exception() raise 
NotImplementedError.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32363>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to