Skip to content

Commit 077f287

Browse files
committed
upgrade mypy and moved linting to ruff
1 parent e220674 commit 077f287

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

.github/workflows/test_full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
13+
python-version: ['3.8', '3.9', '3.10', '3.11']
1414

1515
steps:
1616
- uses: actions/checkout@v3

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ install-full: ## Install dependencies
1919

2020
lint: ## Run code linters
2121
black --check ellar_throttler tests
22-
isort --check ellar_throttler tests
23-
autoflake --remove-unused-variables --remove-unused-variables -r ellar_throttler tests
24-
flake8 ellar_throttler tests
22+
ruff check ellar_throttler tests
2523
mypy ellar_throttler
2624

2725
fmt format: ## Run code formatters
2826
black ellar_throttler tests
29-
isort ellar_throttler tests
27+
ruff check --fix ellar_throttler tests
3028

3129
test: ## Run tests
3230
pytest tests

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="#" target="blank"><img src="docs/img/EllarLogoIconOnly.png" width="200" alt="Ellar Logo" /></a>
2+
<a href="#" target="blank"><img src="https://eadwincode.github.io/ellar/img/EllarLogoB.png" width="200" alt="Ellar Logo" /></a>
33
</p>
44

5-
<p align="center">A rate limiting module for Ellar</p>
5+
<p align="center">Ellar - Python ASGI web framework for building fast, efficient and scalable RESTful APIs and server-side application.</p>
66

77
![Test](https://github.com/eadwinCode/ellar-throttler/actions/workflows/test_full.yml/badge.svg)
88
![Coverage](https://img.shields.io/codecov/c/github/eadwinCode/ellar-throttler)

ellar_throttler/exception.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class ThrottledException(APIException):
1111
extra_detail_singular = "Expected available in {wait} second."
1212
extra_detail_plural = "Expected available in {wait} seconds."
1313

14-
def __init__(self, wait: float = None, detail: t.Any = None) -> None:
14+
def __init__(
15+
self, wait: t.Optional[float] = None, detail: t.Optional[t.Any] = None
16+
) -> None:
1517
if detail is None:
1618
detail = self.default_detail
1719
if wait is not None:

ellar_throttler/module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def setup(
1616
cls,
1717
ttl: int,
1818
limit: int,
19-
storage: t.Union[t.Type, t.Any] = None,
20-
skip_if: t.Callable[[IExecutionContext], bool] = None,
19+
storage: t.Union[t.Type, t.Any, None] = None,
20+
skip_if: t.Optional[t.Callable[[IExecutionContext], bool]] = None,
2121
) -> DynamicModule:
2222
if storage and isinstance(storage, IThrottlerStorage):
2323
_provider = ProviderConfig(IThrottlerStorage, use_value=storage)
@@ -28,7 +28,7 @@ def setup(
2828
IThrottlerStorage, use_class=ThrottlerStorageService
2929
)
3030

31-
return DynamicModule( # type:ignore
31+
return DynamicModule(
3232
cls,
3333
providers=[
3434
_provider,

ellar_throttler/throttler_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def storage(self) -> t.Any: # pragma: no cover
8484
return self._cache_service.get_backend()
8585

8686
async def get_expiration_time(self, key: str) -> int:
87-
result = await self._cache_service.get_async(f"{key}-ttl")
87+
result: int = await self._cache_service.get_async(f"{key}-ttl")
8888
return math.floor(result - time.time()) if result else -1
8989

9090
async def increment(self, key: str, ttl: int) -> ThrottlerStorageRecord:

pyproject.toml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,33 @@ Homepage = "https://eadwincode.github.io/ellar-throttler/"
5454
test = [
5555
"pytest >= 7.1.3,<8.0.0",
5656
"pytest-cov >= 2.12.0,<5.0.0",
57-
"mypy == 0.971",
58-
"flake8 >= 3.8.3,<7.0.0",
57+
"mypy == 1.4.1",
58+
"ruff ==0.0.275",
5959
"black ==22.8.0",
60-
"isort >=5.0.6,<6.0.0",
6160
"pytest-asyncio",
6261
"autoflake",
6362
]
6463
dev = [
6564
"pre-commit"
6665
]
66+
67+
[tool.ruff]
68+
select = [
69+
"E", # pycodestyle errors
70+
"W", # pycodestyle warnings
71+
"F", # pyflakes
72+
"I", # isort
73+
"C", # flake8-comprehensions
74+
"B", # flake8-bugbear
75+
]
76+
ignore = [
77+
"E501", # line too long, handled by black
78+
"B008", # do not perform function calls in argument defaults
79+
"C901", # too complex
80+
]
81+
82+
[tool.ruff.per-file-ignores]
83+
"__init__.py" = ["F401"]
84+
85+
[tool.ruff.isort]
86+
known-third-party = ["ellar",]

tests/test_throttler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_skip_configure(self):
9494
)
9595

9696
_client = test_module.get_test_client()
97-
for i in range(15):
97+
for _i in range(15):
9898
res = _client.get("/")
9999

100100
assert res.status_code == 200
@@ -115,7 +115,7 @@ class TestThrottlerStorageServiceConfiguration:
115115
ControllerModule,
116116
),
117117
global_guards=[ThrottlerGuard],
118-
config_module=dict(CACHES={"default": LocalMemCacheBackend()}),
118+
config_module={"CACHES": {"default": LocalMemCacheBackend()}},
119119
)
120120

121121
test_module_use_value = Test.create_test_module(

0 commit comments

Comments
 (0)