Skip to content

Commit

Permalink
Python 3.12 and minor cleanup (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Jan 20, 2024
1 parent 2b8fe0a commit acd3ffe
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
needs: lint
strategy:
matrix:
pyver: ['3.9', '3.10', '3.11']
pyver: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down
7 changes: 2 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Implementation is almost direct port from this patch_.
Example
-------

Requires Python 3.5.3+

.. code:: python
import asyncio
Expand All @@ -53,8 +51,7 @@ Requires Python 3.5.3+
await asyncio.sleep(0.1)
loop = asyncio.get_event_loop()
loop.run_until_complete(go())
asyncio.run(go())
Fast path
Expand Down Expand Up @@ -85,5 +82,5 @@ License
``aiorwlock`` is offered under the Apache 2 license.


.. _asyncio: http://docs.python.org/3.8/library/asyncio.html
.. _asyncio: http://docs.python.org/3/library/asyncio.html
.. _patch: http://bugs.python.org/issue8800
17 changes: 5 additions & 12 deletions aiorwlock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import asyncio
import threading
from collections import deque
from typing import Any, Deque, List, Optional, Tuple

Loop = asyncio.AbstractEventLoop
OptLoop = Optional[Loop]

# silence LGTM service alerts
Future = asyncio.Future
Task = asyncio.Task
from typing import Any, Deque, List, Tuple

__version__ = '1.3.0'
__all__ = ('RWLock',)
Expand All @@ -28,14 +21,14 @@ class _RWLockCore:

def __init__(self, fast: bool):
self._do_yield = not fast
self._read_waiters: Deque[Future[None]] = deque()
self._write_waiters: Deque[Future[None]] = deque()
self._read_waiters: Deque[asyncio.Future[None]] = deque()
self._write_waiters: Deque[asyncio.Future[None]] = deque()
self._r_state: int = 0
self._w_state: int = 0
# tasks will be few, so a list is not inefficient
self._owning: List[Tuple[Task[Any], int]] = []
self._owning: List[Tuple[asyncio.Task[Any], int]] = []

def _get_loop(self) -> Loop:
def _get_loop(self) -> asyncio.AbstractEventLoop:
"""
From: https://github.com/python/cpython/blob/3.12/Lib/asyncio/mixins.py
"""
Expand Down
3 changes: 1 addition & 2 deletions examples/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ async def go():
await asyncio.sleep(0.1)


loop = asyncio.get_event_loop()
loop.run_until_complete(go())
asyncio.run(go())
3 changes: 1 addition & 2 deletions examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ async def go():
rwlock.writer_lock.release()


loop = asyncio.get_event_loop()
loop.run_until_complete(go())
asyncio.run(go())
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
bandit==1.7.6; implementation_name=="cpython"
black==23.12.1; implementation_name=="cpython"
flake8-bugbear==24.1.17; implementation_name=="cpython"
flake8-quotes==3.3.2; implementation_name=="cpython"
flake8==7.0.0; implementation_name=="cpython"
isort==5.13.2; implementation_name=="cpython"
mypy==1.8.0; implementation_name=="cpython"
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from setuptools import setup

install_requires = []


def read(f):
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
Expand All @@ -27,10 +25,11 @@ def read_version():
'License :: OSI Approved :: Apache Software License',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
'Operating System :: OS Independent',
'Development Status :: 4 - Beta',
'Framework :: AsyncIO',
Expand All @@ -55,10 +54,10 @@ def read_version():
download_url='https://pypi.python.org/pypi/aiorwlock',
license='Apache 2',
packages=['aiorwlock'],
install_requires=install_requires,
install_requires=(),
keywords=['aiorwlock', 'lock', 'asyncio'],
zip_safe=True,
project_urls=project_urls,
python_requires='>=3.7.0',
python_requires=">=3.8",
include_package_data=True,
)
1 change: 0 additions & 1 deletion tests/test_corner_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ async def write_wait(lock):
seq.append('FIN1')

async def write(lock):
await asyncio.sleep(0) # PY36 seems to run tasks in the wrong order.
async with lock.writer:
seq.append('START2')
await asyncio.sleep(0.1)
Expand Down

0 comments on commit acd3ffe

Please sign in to comment.