Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-ast
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: tests/fixtures/
- id: end-of-file-fixer
exclude: tests/fixtures/
- id: check-yaml
exclude: tests/fixtures/
- id: debug-statements
exclude: tests/fixtures/
- id: requirements-txt-fixer
exclude: tests/fixtures/
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.14.0
hooks:
- id: reorder-python-imports
args: [--py37-plus]
exclude: tests/fixtures/
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
exclude: tests/fixtures/
args:
- --line-length=120
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --in-place]
exclude: tests/fixtures/
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
exclude: tests/fixtures/
args:
- --max-line-length=120
- --extend-ignore=W503,E203
additional_dependencies:
- flake8-string-format
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Requirements

* Python 3.8+
* Python 3.9+
* Django 4.1+

We **highly recommend** and only officially support the latest patch release of
Expand Down Expand Up @@ -128,7 +128,7 @@ serializers.py

```python
from adrf.serializers import Serializer
from rest_framework import serializers
from adrf import serializers

class AsyncSerializer(Serializer):
username = serializers.CharField()
Expand Down
31 changes: 8 additions & 23 deletions adrf/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ def decorator(func):
# WrappedAPIView.__doc__ = func.doc <--- Not possible to do this

# api_view applied without (method_names)
assert not (
isinstance(http_method_names, types.FunctionType)
), "@api_view missing list of allowed HTTP methods"
assert not (isinstance(http_method_names, types.FunctionType)), "@api_view missing list of allowed HTTP methods"

# api_view applied with eg. string instead of list of strings
assert isinstance(http_method_names, (list, tuple)), (
"@api_view expected a list of strings, received %s"
% type(http_method_names).__name__
"@api_view expected a list of strings, received %s" % type(http_method_names).__name__
)

allowed_methods = set(http_method_names) | {"options"}
WrappedAPIView.http_method_names = [
method.lower() for method in allowed_methods
]
WrappedAPIView.http_method_names = [method.lower() for method in allowed_methods]

view_is_async = asyncio.iscoroutinefunction(func)

Expand All @@ -55,25 +50,15 @@ def handler(self, *args, **kwargs):
WrappedAPIView.__name__ = func.__name__
WrappedAPIView.__module__ = func.__module__

WrappedAPIView.renderer_classes = getattr(
func, "renderer_classes", APIView.renderer_classes
)
WrappedAPIView.renderer_classes = getattr(func, "renderer_classes", APIView.renderer_classes)

WrappedAPIView.parser_classes = getattr(
func, "parser_classes", APIView.parser_classes
)
WrappedAPIView.parser_classes = getattr(func, "parser_classes", APIView.parser_classes)

WrappedAPIView.authentication_classes = getattr(
func, "authentication_classes", APIView.authentication_classes
)
WrappedAPIView.authentication_classes = getattr(func, "authentication_classes", APIView.authentication_classes)

WrappedAPIView.throttle_classes = getattr(
func, "throttle_classes", APIView.throttle_classes
)
WrappedAPIView.throttle_classes = getattr(func, "throttle_classes", APIView.throttle_classes)

WrappedAPIView.permission_classes = getattr(
func, "permission_classes", APIView.permission_classes
)
WrappedAPIView.permission_classes = getattr(func, "permission_classes", APIView.permission_classes)

WrappedAPIView.schema = getattr(func, "schema", APIView.schema)

Expand Down
Loading