Author yselivanov
Recipients asvetlov, yselivanov
Date 2017-12-19.03:39:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1513654793.7.0.213398074469.issue32363@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-12-19 03:39:53yselivanovsetrecipients: + yselivanov, asvetlov
2017-12-19 03:39:53yselivanovsetmessageid: <1513654793.7.0.213398074469.issue32363@psf.upfronthosting.co.za>
2017-12-19 03:39:53yselivanovlinkissue32363 messages
2017-12-19 03:39:53yselivanovcreate