bamthomas / aioimaplib

Python asyncio IMAP4rev1 client library
GNU General Public License v3.0
138 stars 59 forks source link

aioimap: using await/async syntax #59

Closed bamthomas closed 3 years ago

bamthomas commented 3 years ago

as mentioned in #52 it is legit to go from @coroutine python 3.4 style to python 3.5 async/await (as python 3.5 is not even maintained)

If it is ok for everyone I will merge this next week

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.04%) to 95.794% when pulling 0235f84f87b544fb4156c2538e3ab20514b3bde9 on async_await into c59cf4f7ba58ab1fd3fea7aa1dbf10ae651725d3 on master.

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-1.05%) to 95.902% when pulling 631d94ffc974a5ea4dfea5053e7b2b3d0ef0bb5e on async_await into d145aa00cb70a000b1a4182b7760b5b7434e2de5 on master.

Lithimlin commented 3 years ago

On this branch, I am getting the following Error for the Condition object:

Traceback (most recent call last):
  File ".../async-test.py", line 28, in <module>
    get_event_loop().run_until_complete(check_mailbox('IMAP_SERVER', 'IMAP_USER', 'IMAP_PASSWORD'))
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File ".../async-test.py", line 16, in check_mailbox
    await imap_client.wait_hello_from_server()
  File ".../aioimaplib/aioimaplib.py", line 686, in wait_hello_from_server
    await asyncio.wait_for(self.protocol.wait('AUTH|NONAUTH'), self.timeout)
  File "/usr/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
    return fut.result()
  File ".../aioimaplib/aioimaplib.py", line 595, in wait
    with (await self.state_condition):
TypeError: object Condition can't be used in 'await' expression
bamthomas commented 3 years ago

which python version ?

weird CI was green and it was green here but you're right the doc is saying that it should be

async with cond:
    await cond.wait()

not sure that async with... is same as with async...

I will have a look on thursday

Lithimlin commented 3 years ago

I'm on version 3.9, so the newest. For new projects I usually try to stick with the newest versions so I don't get confused when a feature I try to use doesn't work.

Lithimlin commented 3 years ago

Just wanted to let you know that in line 594, you still have with await self.state_condition: instead of async with self.state_condition:, causing a TypeError to be raised.

Lithimlin commented 3 years ago

With that fixed, I get the following:

Task exception was never retrieved
future: <Task finished name='Task-2' coro=<BaseEventLoop.create_connection() done, defined at /usr/lib/python3.9/asyncio/base_events.py:967> exception=gaierror(-2, 'Name or service not known')>
bamthomas commented 3 years ago

It should be related to python 3.9 I guess. I will try to test with 3.9 (didn't manage to install virtualenv with it)