Skip to content

Commit

Permalink
[3.8] bpo-36373: Fix deprecation warnings (GH-15889) (GH-15901)
Browse files Browse the repository at this point in the history
https://bugs.python.org/issue36373
(cherry picked from commit 7264e92)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
  • Loading branch information
asvetlov committed Sep 11, 2019
1 parent 80db4b4 commit 4601f7a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Lib/asyncio/locks.py
Expand Up @@ -332,7 +332,7 @@ def __init__(self, lock=None, *, loop=None):
DeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=2)


if lock is None: if lock is None:
lock = Lock(loop=self._loop) lock = Lock(loop=loop)
elif lock._loop is not self._loop: elif lock._loop is not self._loop:
raise ValueError("loop argument must agree with lock") raise ValueError("loop argument must agree with lock")


Expand Down
2 changes: 1 addition & 1 deletion Lib/asyncio/queues.py
Expand Up @@ -45,7 +45,7 @@ def __init__(self, maxsize=0, *, loop=None):
# Futures. # Futures.
self._putters = collections.deque() self._putters = collections.deque()
self._unfinished_tasks = 0 self._unfinished_tasks = 0
self._finished = locks.Event(loop=self._loop) self._finished = locks.Event(loop=loop)
self._finished.set() self._finished.set()
self._init(maxsize) self._init(maxsize)


Expand Down
7 changes: 3 additions & 4 deletions Lib/test/test_asyncio/test_locks.py
Expand Up @@ -500,10 +500,9 @@ def test_ctor_loop(self):
self.assertIs(cond._loop, self.loop) self.assertIs(cond._loop, self.loop)


def test_ctor_noloop(self): def test_ctor_noloop(self):
with self.assertWarns(DeprecationWarning): asyncio.set_event_loop(self.loop)
asyncio.set_event_loop(self.loop) cond = asyncio.Condition()
cond = asyncio.Condition() self.assertIs(cond._loop, self.loop)
self.assertIs(cond._loop, self.loop)


def test_wait(self): def test_wait(self):
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_asyncio/test_queues.py
Expand Up @@ -83,8 +83,7 @@ def test_ctor_loop(self):


def test_ctor_noloop(self): def test_ctor_noloop(self):
asyncio.set_event_loop(self.loop) asyncio.set_event_loop(self.loop)
with self.assertWarns(DeprecationWarning): q = asyncio.Queue()
q = asyncio.Queue()
self.assertIs(q._loop, self.loop) self.assertIs(q._loop, self.loop)


def test_repr(self): def test_repr(self):
Expand Down
10 changes: 6 additions & 4 deletions Lib/unittest/async_case.py
Expand Up @@ -89,8 +89,9 @@ def _callMaybeAsync(self, func, /, *args, **kwargs):
else: else:
return ret return ret


async def _asyncioLoopRunner(self): async def _asyncioLoopRunner(self, fut):
queue = self._asyncioCallsQueue self._asyncioCallsQueue = queue = asyncio.Queue()
fut.set_result(None)
while True: while True:
query = await queue.get() query = await queue.get()
queue.task_done() queue.task_done()
Expand All @@ -113,8 +114,9 @@ def _setupAsyncioLoop(self):
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
loop.set_debug(True) loop.set_debug(True)
self._asyncioTestLoop = loop self._asyncioTestLoop = loop
self._asyncioCallsQueue = asyncio.Queue(loop=loop) fut = loop.create_future()
self._asyncioCallsTask = loop.create_task(self._asyncioLoopRunner()) self._asyncioCallsTask = loop.create_task(self._asyncioLoopRunner(fut))
loop.run_until_complete(fut)


def _tearDownAsyncioLoop(self): def _tearDownAsyncioLoop(self):
assert self._asyncioTestLoop is not None assert self._asyncioTestLoop is not None
Expand Down

0 comments on commit 4601f7a

Please sign in to comment.