Skip to content

Commit c751f33

Browse files
committed
fix(lint): exclude framework files from ty/pyrefly and fix pyrefly invocation
1 parent c615cf9 commit c751f33

File tree

12 files changed

+82
-62
lines changed

12 files changed

+82
-62
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ lint:
44
uv run ruff format .
55
uv run ruff check --fix .
66
uv run ty check .
7-
uv run pyrefly check .
7+
uv run pyrefly check
88
uv run bandit -c pyproject.toml -r src examples -q

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,32 @@ doctest_optionflags = [
171171
]
172172
testpaths = ["src", "tests"]
173173

174+
[tool.ty.src]
175+
exclude = [
176+
# Django ORM descriptors / manager not understood by ty
177+
"src/fastapi_api_key/django/",
178+
# Litestar DI / State / Request not understood by ty
179+
"src/fastapi_api_key/litestar_api.py",
180+
# Quart abort() is NoReturn but not recognised; TestClient __aexit__
181+
"src/fastapi_api_key/quart_api.py",
182+
"tests/unit/test_quart_api.py",
183+
]
184+
174185
[tool.pyrefly]
175186
project-includes = [
176187
"**/*.py*",
177188
"**/*.ipynb",
178189
]
190+
project_excludes = [
191+
# Django ORM descriptors / manager not understood by pyrefly
192+
"src/fastapi_api_key/django/*.py",
193+
# Litestar DI / State / Request not understood by pyrefly
194+
"src/fastapi_api_key/litestar_api.py",
195+
# Quart abort() is NoReturn but not recognised; TestClient __aexit__
196+
"src/fastapi_api_key/quart_api.py",
197+
"tests/unit/test_quart_api.py",
198+
"tests/unit/test_litestar_api.py",
199+
]
179200

180201

181202
[tool.coverage.run]

src/fastapi_api_key/django/apps.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
try:
99
from django.apps import AppConfig
1010
except ModuleNotFoundError as e: # pragma: no cover
11-
raise ImportError(
12-
"Django integration requires 'django'. "
13-
"Install it with: uv add fastapi_api_key[django]"
14-
) from e
11+
raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e
1512

1613

1714
class FastApiApiKeyDjangoConfig(AppConfig):

src/fastapi_api_key/django/decorators.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ async def my_view(request):
1616
try:
1717
from django.http import HttpRequest, JsonResponse
1818
except ModuleNotFoundError as e: # pragma: no cover
19-
raise ImportError(
20-
"Django integration requires 'django'. "
21-
"Install it with: uv add fastapi_api_key[django]"
22-
) from e
19+
raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e
2320

2421
from fastapi_api_key.domain.errors import (
2522
InvalidKey,

src/fastapi_api_key/django/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
import django # noqa: F401
1818
from django.db import models
1919
except ModuleNotFoundError as e: # pragma: no cover
20-
raise ImportError(
21-
"Django integration requires 'django'. "
22-
"Install it with: uv add fastapi_api_key[django]"
23-
) from e
20+
raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e
2421

2522

2623
class ApiKeyModel(models.Model):

src/fastapi_api_key/django/repository.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
"""
1111

1212
import sys
13-
from datetime import datetime
1413
from typing import List, Optional
1514

1615
try:
1716
from django.db import models as _dj # noqa: F401
1817
except ModuleNotFoundError as e: # pragma: no cover
19-
raise ImportError(
20-
"Django integration requires 'django'. "
21-
"Install it with: uv add fastapi_api_key[django]"
22-
) from e
18+
raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e
2319

24-
from django.db.models import Q
2520

2621
from fastapi_api_key.domain.entities import ApiKey
2722
from fastapi_api_key.repositories.base import AbstractApiKeyRepository, ApiKeyFilter

src/fastapi_api_key/django/urls.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
try:
1616
from django.urls import path
1717
except ModuleNotFoundError as e: # pragma: no cover
18-
raise ImportError(
19-
"Django integration requires 'django'. "
20-
"Install it with: uv add fastapi_api_key[django]"
21-
) from e
18+
raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e
2219

2320
from fastapi_api_key.services.base import AbstractApiKeyService
2421
from fastapi_api_key.django.views import (

src/fastapi_api_key/django/views.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@
2626
"""
2727

2828
import json
29-
from typing import Any, Awaitable, Callable, List, Optional
29+
from typing import Any, Awaitable, Callable
3030

3131
try:
3232
from django.http import HttpRequest, JsonResponse
3333
from django.views import View
3434
except ModuleNotFoundError as e: # pragma: no cover
35-
raise ImportError(
36-
"Django integration requires 'django'. "
37-
"Install it with: uv add fastapi_api_key[django]"
38-
) from e
35+
raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e
3936

4037
from pydantic import ValidationError
4138

@@ -45,7 +42,6 @@
4542
ApiKeyCountOut,
4643
ApiKeyCreateIn,
4744
ApiKeyCreatedOut,
48-
ApiKeyOut,
4945
ApiKeySearchIn,
5046
ApiKeySearchOut,
5147
ApiKeyUpdateIn,
@@ -109,7 +105,7 @@ async def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Any
109105
return await super().dispatch(request, *args, **kwargs)
110106
except _HttpError as exc:
111107
return _error(exc.status, exc.detail)
112-
except KeyNotFound as exc:
108+
except KeyNotFound:
113109
return _error(404, "API key not found")
114110

115111
http_method_names = ["get", "post", "patch", "delete", "head", "options"]
@@ -301,7 +297,7 @@ async def post(self, request: HttpRequest) -> JsonResponse:
301297
api_key=payload.api_key,
302298
required_scopes=payload.required_scopes,
303299
)
304-
except (InvalidKey, KeyNotFound) as exc:
300+
except (InvalidKey, KeyNotFound):
305301
return _error(401, "API key invalid")
306302
except KeyNotProvided:
307303
return _error(401, "API key missing")

src/fastapi_api_key/litestar_api.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ async def provide_svc() -> ApiKeyService:
2828
import litestar # noqa: F401
2929
except ModuleNotFoundError as e: # pragma: no cover
3030
raise ImportError(
31-
"Litestar integration requires 'litestar'. "
32-
"Install it with: uv add fastapi_api_key[litestar]"
31+
"Litestar integration requires 'litestar'. Install it with: uv add fastapi_api_key[litestar]"
3332
) from e
3433

3534
from typing import Awaitable, Callable, List, Optional
@@ -38,7 +37,6 @@ async def provide_svc() -> ApiKeyService:
3837
from litestar.connection import ASGIConnection
3938
from litestar.di import Provide
4039
from litestar.exceptions import (
41-
HTTPException,
4240
NotAuthorizedException,
4341
NotFoundException,
4442
PermissionDeniedException,
@@ -228,9 +226,7 @@ async def get_api_key(self, api_key_id: str, svc: AbstractApiKeyService) -> ApiK
228226
return _to_out(entity)
229227

230228
@patch("/{api_key_id:str}", status_code=HTTP_200_OK, summary="Update an API key")
231-
async def update_api_key(
232-
self, api_key_id: str, data: ApiKeyUpdateIn, svc: AbstractApiKeyService
233-
) -> ApiKeyOut:
229+
async def update_api_key(self, api_key_id: str, data: ApiKeyUpdateIn, svc: AbstractApiKeyService) -> ApiKeyOut:
234230
"""Partially update an API key.
235231
236232
Args:

src/fastapi_api_key/quart_api.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ async def protected():
3737
try:
3838
import quart # noqa: F401
3939
except ModuleNotFoundError as e: # pragma: no cover
40-
raise ImportError(
41-
"Quart integration requires 'quart'. "
42-
"Install it with: uv add fastapi_api_key[quart]"
43-
) from e
40+
raise ImportError("Quart integration requires 'quart'. Install it with: uv add fastapi_api_key[quart]") from e
4441

45-
import json
4642
from functools import wraps
4743
from typing import Any, Awaitable, Callable, List, Optional
4844

@@ -62,7 +58,6 @@ async def protected():
6258
ApiKeyCountOut,
6359
ApiKeyCreateIn,
6460
ApiKeyCreatedOut,
65-
ApiKeyOut,
6661
ApiKeySearchIn,
6762
ApiKeySearchOut,
6863
ApiKeyUpdateIn,

0 commit comments

Comments
 (0)