Skip to content

Commit

Permalink
Drop support for Python 3.6
Browse files Browse the repository at this point in the history
Closes #62
  • Loading branch information
mjpieters committed Oct 30, 2021
1 parent 2b22441 commit ba525ef
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 28 deletions.
1 change: 0 additions & 1 deletion .azure-pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ stages:
- template: stage-test.yml
parameters:
pythonVersions:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
2 changes: 0 additions & 2 deletions .azure-pipelines/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ stages:
- template: stage-test.yml
parameters:
pythonVersions:
- "3.6"
- "3.7"
- "3.8"
- "3.9"

- template: stage-deploy.yml
parameters:
pythonVersions:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ https://aiolimiter.readthedocs.io
$ pip install aiolimiter
```

The library requires Python 3.6 or newer.
The library requires Python 3.7 or newer.

## Requirements

- Python >= 3.6
- Python >= 3.7

## License

Expand Down
1 change: 1 addition & 0 deletions changelog.d/62.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dropped support for Python 3.6
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Installation
$ pip install aiolimiter
The library requires Python 3.6 or newer.
The library requires Python 3.7 or newer.

Requirements
------------

- Python >= 3.6
- Python >= 3.7


Usage
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include = ["CHANGELOG.md"]
"GitHub: issues" = "https://github.com/mjpieters/aiolimiter/issues"

[tool.poetry.dependencies]
python = "^3.6.1"
python = "^3.7"
importlib_metadata = { version = ">=1.3,<5.0", python = "< 3.8" }
sphinx = {version = ">=4.2.0,<5.0.0", optional = true}
aiohttp-theme = {version = "^0.1.6", optional = true}
Expand Down
2 changes: 1 addition & 1 deletion src/aiolimiter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Python 3.8+
from importlib.metadata import version # type: ignore
except ImportError:
# Python 3.6, 3.7
# Python 3.7
from importlib_metadata import version # type: ignore

from .leakybucket import AsyncLimiter
Expand Down
13 changes: 0 additions & 13 deletions src/aiolimiter/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@

# compatibility across Python versions
import asyncio
import contextlib
import sys

try:
# Python 3.7 or newer
AsyncContextManagerBase = contextlib.AbstractAsyncContextManager
current_task = asyncio.current_task
get_running_loop = asyncio.get_running_loop
except AttributeError: # pragma: no cover
# Python 3.6
AsyncContextManagerBase = object # type: ignore
current_task = asyncio.Task.current_task
get_running_loop = asyncio.get_event_loop


if sys.version_info < (3, 8): # pragma: no cover
wait_for = asyncio.wait_for
else:
Expand Down
11 changes: 6 additions & 5 deletions src/aiolimiter/leakybucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
# Licensed under the MIT license as detailed in LICENSE.txt

import asyncio
from contextlib import AbstractAsyncContextManager
from types import TracebackType
from typing import Dict, Optional, Type

from .compat import AsyncContextManagerBase, current_task, get_running_loop, wait_for
from .compat import wait_for


class AsyncLimiter(AsyncContextManagerBase):
class AsyncLimiter(AbstractAsyncContextManager):
"""A leaky bucket rate limiter.
This is an :ref:`asynchronous context manager <async-context-managers>`;
Expand Down Expand Up @@ -43,7 +44,7 @@ def __init__(self, max_rate: float, time_period: float = 60) -> None:

def _leak(self) -> None:
"""Drip out capacity from the bucket."""
loop = get_running_loop()
loop = asyncio.get_running_loop()
if self._level:
# drip out enough level for the elapsed time since
# we last checked
Expand Down Expand Up @@ -84,8 +85,8 @@ async def acquire(self, amount: float = 1) -> None:
if amount > self.max_rate:
raise ValueError("Can't acquire more than the maximum capacity")

loop = get_running_loop()
task = current_task(loop)
loop = asyncio.get_running_loop()
task = asyncio.current_task(loop)
assert task is not None
while not self.has_capacity(amount):
# wait for the next drip to have left the bucket
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist = True
envlist = py36, py37, py38, py39, py310, pypy3
envlist = py37, py38, py39, py310, pypy3

[testenv]
whitelist_externals = poetry
Expand Down

0 comments on commit ba525ef

Please sign in to comment.