Skip to content

Commit

Permalink
Get aiorwlock.__version__ from package metadata (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Nov 25, 2024
1 parent 1577030 commit 61362ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ frequently searched is an ideal candidate for the use of a read-write lock.
However, if updates become frequent then the data spends most of its time
being exclusively locked and there is little, if any increase in concurrency.

**Note:** a task that *acquires* the lock should be used for *releasing* it.
Locking from one task and releasing from another one generates ``RuntimeError``.


Implementation is almost direct port from this patch_.

Expand Down
18 changes: 14 additions & 4 deletions aiorwlock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
from collections import deque
from typing import Any, Deque, List, Tuple

__version__ = "1.4.0"
__all__ = ('RWLock',)
__all__ = ('RWLock', '__version__')


def __getattr__(name: str) -> object:
global __version__

if name == "__version__":
from importlib.metadata import version
__version__ = version("aiorwlock")
return __version__

raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


# implementation based on:
Expand Down Expand Up @@ -145,8 +155,8 @@ def _release(self, lock_type: int) -> None:

try:
self._owning.remove((me, lock_type))
except ValueError:
raise RuntimeError('Cannot release an un-acquired lock')
except ValueError as exc:
raise RuntimeError('Cannot release an un-acquired lock') from exc
if lock_type == self._RL:
self._r_state -= 1
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import aiorwlock


def test_version() -> None:
ver = aiorwlock.__version__
assert isinstance(ver, str)

0 comments on commit 61362ec

Please sign in to comment.