Skip to content

Commit

Permalink
Fix incorrect return annotation in asyncio.lock (#2155)
Browse files Browse the repository at this point in the history
NoReturn should be used only when the function never returns. In this case, the awaitable returns None if releasing the lock succeeds, so `Awaitable[None]` is right.

Noticed this while reviewing python/typeshed#7676
  • Loading branch information
JelleZijlstra authored May 2, 2022
1 parent 09a52db commit eca7075
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions redis/asyncio/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import threading
import uuid
from types import SimpleNamespace
from typing import TYPE_CHECKING, Awaitable, NoReturn, Optional, Union
from typing import TYPE_CHECKING, Awaitable, Optional, Union

from redis.exceptions import LockError, LockNotOwnedError

Expand Down Expand Up @@ -243,15 +243,15 @@ async def owned(self) -> bool:
stored_token = encoder.encode(stored_token)
return self.local.token is not None and stored_token == self.local.token

def release(self) -> Awaitable[NoReturn]:
def release(self) -> Awaitable[None]:
"""Releases the already acquired lock"""
expected_token = self.local.token
if expected_token is None:
raise LockError("Cannot release an unlocked lock")
self.local.token = None
return self.do_release(expected_token)

async def do_release(self, expected_token: bytes):
async def do_release(self, expected_token: bytes) -> None:
if not bool(
await self.lua_release(
keys=[self.name], args=[expected_token], client=self.redis
Expand Down

0 comments on commit eca7075

Please sign in to comment.