Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.

Commit 86a4d8e

Browse files
Update type hints (#24)
* Update type hints * Update middlewares.py * f * Update poetry.lock * up * Update CI.yml * Update CI.yml * up * Update CI.yml * Update CI.yml * Update middlewares.py * Update CI.yml * Update pyproject.toml * Update poetry.lock * Update CI.yml * Update CI.yml * Update CI.yml
1 parent 1df6329 commit 86a4d8e

File tree

4 files changed

+45
-37
lines changed

4 files changed

+45
-37
lines changed

.github/workflows/CI.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,33 @@ on:
44
workflow_dispatch:
55
pull_request:
66
types: [assigned, opened, synchronize, reopened]
7+
78
permissions:
89
contents: write
910
pull-requests: write
11+
1012
jobs:
1113
test:
1214
runs-on: ubuntu-latest
1315
strategy:
16+
fail-fast: false
1417
matrix:
15-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
18+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
1619
django-version: ['3.2', '4.0', '4.1', '4.2', '5.0', '5.1']
17-
fail-fast: false
20+
21+
exclude:
22+
# Python 3.9
23+
- python-version: '3.9'
24+
django-version: '5.0'
25+
- python-version: '3.9'
26+
django-version: '5.1'
27+
28+
# Python 3.13
29+
- python-version: '3.13'
30+
django-version: '3.2'
31+
- python-version: '3.13'
32+
django-version: '4.0'
33+
1834
steps:
1935
- uses: actions/checkout@v3
2036
- name: Set up Python ${{ matrix.python-version }}
@@ -26,26 +42,13 @@ jobs:
2642
with:
2743
virtualenvs-create: true
2844
virtualenvs-in-project: true
29-
- name: Determine Django compatibility
30-
id: check-django
31-
run: |
32-
if [[ "${{ matrix.python-version }}" == "3.8" && "${{ matrix.django-version }}" > "4.1" ]]; then
33-
echo "compatible=false" >> $GITHUB_OUTPUT
34-
elif [[ "${{ matrix.python-version }}" == "3.9" && "${{ matrix.django-version }}" > "4.2" ]]; then
35-
echo "compatible=false" >> $GITHUB_OUTPUT
36-
elif [[ "${{ matrix.python-version }}" < "3.10" && "${{ matrix.django-version }}" == "5.0" ]]; then
37-
echo "compatible=false" >> $GITHUB_OUTPUT
38-
else
39-
echo "compatible=true" >> $GITHUB_OUTPUT
40-
fi
4145
- name: Install dependencies
42-
if: steps.check-django.outputs.compatible == 'true'
4346
run: |
44-
poetry install --sync --no-interaction --no-root
47+
poetry install --sync --no-interaction --no-root
4548
poetry run pip install "django==${{ matrix.django-version }}.*"
4649
- name: Run tests
47-
if: steps.check-django.outputs.compatible == 'true'
4850
run: poetry run pytest .
51+
4952
merge:
5053
runs-on: ubuntu-latest
5154
needs: [test]
@@ -57,6 +60,7 @@ jobs:
5760
env:
5861
PR_URL: ${{github.event.pull_request.html_url}}
5962
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
63+
6064
release:
6165
runs-on: ubuntu-latest
6266
if: "startsWith(github.ref, 'refs/tags/')"
@@ -70,7 +74,7 @@ jobs:
7074
virtualenvs-in-project: true
7175
- name: Install python dependencies
7276
run: |
73-
poetry install --sync --no-interaction --no-root --with test
77+
poetry install --sync --no-interaction --no-root --with test
7478
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
7579
- name: Publish
7680
run: |

ninja_put_patch_file_upload_middleware/middlewares.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from collections.abc import Callable
2-
from typing import Any
2+
from typing import Any, Union
33

44
from asgiref.sync import iscoroutinefunction, sync_to_async
5-
from django.http import HttpRequest
5+
from django.http import HttpRequest, HttpResponse
66
from django.utils.decorators import sync_and_async_middleware
77

88

99
@sync_and_async_middleware
10-
def process_put_patch(get_response: Callable) -> Callable:
11-
async def async_middleware(request: HttpRequest) -> Any:
10+
def process_put_patch(
11+
get_response: Union[
12+
Callable[[HttpRequest], HttpResponse], Callable[[HttpRequest], Any]
13+
],
14+
) -> Union[Callable[[HttpRequest], Any], Callable[[HttpRequest], HttpResponse]]:
15+
async def async_middleware(request: HttpRequest) -> Union[HttpResponse, Any]:
1216
if (
1317
request.method in ("PUT", "PATCH")
1418
and request.content_type != "application/json"
@@ -22,7 +26,7 @@ async def async_middleware(request: HttpRequest) -> Any:
2226

2327
return await get_response(request)
2428

25-
def sync_middleware(request: HttpRequest) -> Any:
29+
def sync_middleware(request: HttpRequest) -> Union[HttpResponse, Any]:
2630
if (
2731
request.method in ("PUT", "PATCH")
2832
and request.content_type != "application/json"

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ homepage = "https://github.com/baseplate-admin/ninja_put_patch_file_upload_middl
1010
repository = "https://github.com/baseplate-admin/ninja_put_patch_file_upload_middleware"
1111
keywords = ["ninja", "django-ninja", "middlewares",'put','patch','file upload']
1212
classifiers = [
13-
"Development Status :: 5 - Production/Stable",
14-
"Intended Audience :: Developers",
15-
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware",
16-
"Framework :: Django",
17-
"Framework :: Django :: 3.2",
18-
"Framework :: Django :: 4.1",
19-
"Framework :: Django :: 4.2",
20-
"Framework :: Django :: 5.0",
21-
"Framework :: Django :: 5.1",
22-
"Operating System :: OS Independent",
13+
"Development Status :: 5 - Production/Stable",
14+
"Intended Audience :: Developers",
15+
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware",
16+
"Framework :: Django",
17+
"Framework :: Django :: 3.2",
18+
"Framework :: Django :: 4.1",
19+
"Framework :: Django :: 4.2",
20+
"Framework :: Django :: 5.0",
21+
"Framework :: Django :: 5.1",
22+
"Operating System :: OS Independent",
2323
]
2424

2525
[tool.poetry.dependencies]
@@ -29,9 +29,9 @@ django-ninja = "*"
2929

3030

3131
[tool.poetry.group.dev.dependencies]
32-
pytest = ">=7.2.2,<9.0.0"
33-
pytest-django = "^4.8.0"
34-
pytest-asyncio = ">=0.23.6,<0.25.0"
32+
pytest = ">=7.2.2"
33+
pytest-django = ">=4.8.0"
34+
pytest-asyncio = ">=0.23.6"
3535

3636
[build-system]
3737
requires = ["poetry-core"]

0 commit comments

Comments
 (0)