Message290630
When creating a asynchronous context manager if the __aexit__ method is not labeled as async (so it returns None instead of a coroutine) the error has a generic error message:
TypeError: object NoneType can't be used in 'await' expression
Would it be possible to change this so it indicates that it was the context that was invalid not an `await` statement? Since the traceback points to the last statement of the with block it can create very confusing errors if the last statement was an await.
Example:
import asyncio
class Test():
async def __aenter__(self):
print("aenter used")
value = asyncio.Future()
value.set_result(True)
return value
#FORGOT TO MARK AS async !!
def __aexit__(self, *errors):
print("aexit used")
return None
async def my_test():
async with Test() as x:
print("inside async with, now awaiting on", x)
await x
my_test().send(None)
Give the output:
aenter used
inside async with, now awaiting on <Future finished result=True>
aexit used
Traceback (most recent call last):
File ".../test.py", line 19, in <module>
my_test().send(None)
File ".../test.py", line 16, in my_test
await x
TypeError: object NoneType can't be used in 'await' expression
Which indicates to me that `x` was None when it was await-ed for. |
|
Date |
User |
Action |
Args |
2017-03-27 17:24:23 | Tadhg McDonald-Jensen | set | recipients:
+ Tadhg McDonald-Jensen, yselivanov |
2017-03-27 17:24:22 | Tadhg McDonald-Jensen | set | messageid: <1490635462.94.0.877144122619.issue29922@psf.upfronthosting.co.za> |
2017-03-27 17:24:22 | Tadhg McDonald-Jensen | link | issue29922 messages |
2017-03-27 17:24:22 | Tadhg McDonald-Jensen | create | |
|