Can the __contains__
function by adapted to Python asyncio, where the method becomes a coroutine? For example
class A():
async def __contains__(self, a):
return True
async def main():
a = A()
print(2 in a)
Of course this generates the warning
RuntimeWarning: coroutine 'A.__contains__' was never awaited
I assume there needs to be some special version of in
for asyncio, though I've tried several permutations of using await
and in
with no luck.
My real use case of contains
is a wrapper around a database search to check if there is an entity conflict. One case is to check if a user's screen name already exists in a database table, such as 'mike' in Users
Of course I could make my own contains
and do something like User.contains('mike')
but I prefer the beauty of in
.