Skip to content

Commit

Permalink
Update ruff, python version, drop black (#706)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
sobolevn and pre-commit-ci[bot] authored Dec 4, 2024
1 parent 96df7e5 commit 4b38801
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 54 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Setup system dependencies
Expand All @@ -73,7 +73,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']
python-version: ['3.13']
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
fetch-tags: true
- uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'
- name: Install dependencies
run: python3 -m pip install --upgrade build twine
- name: Build
Expand Down
7 changes: 2 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.1
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- id: ruff-format

ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
Expand Down
4 changes: 2 additions & 2 deletions mypy_drf_plugin/lib/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict
from typing import Any

from mypy.nodes import TypeInfo


def get_drf_metadata(info: TypeInfo) -> Dict[str, Any]:
def get_drf_metadata(info: TypeInfo) -> dict[str, Any]:
return info.metadata.setdefault("drf", {})
8 changes: 4 additions & 4 deletions mypy_drf_plugin/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Dict, Optional, Type
from typing import Callable, Optional

from mypy.nodes import TypeInfo
from mypy.plugin import ClassDefContext, Plugin
Expand All @@ -16,10 +16,10 @@ def transform_serializer_class(ctx: ClassDefContext) -> None:


class NewSemanalDRFPlugin(Plugin):
def _get_currently_defined_serializers(self) -> Dict[str, int]:
def _get_currently_defined_serializers(self) -> dict[str, int]:
base_serializer_sym = self.lookup_fully_qualified(fullnames.BASE_SERIALIZER_FULLNAME)
if base_serializer_sym is not None and isinstance(base_serializer_sym.node, TypeInfo):
serializer_bases: Dict[str, int] = base_serializer_sym.node.metadata.setdefault("drf", {}).setdefault(
serializer_bases: dict[str, int] = base_serializer_sym.node.metadata.setdefault("drf", {}).setdefault(
"serializer_bases", {fullnames.BASE_SERIALIZER_FULLNAME: 1}
)
return serializer_bases
Expand All @@ -32,5 +32,5 @@ def get_base_class_hook(self, fullname: str) -> Optional[Callable[[ClassDefConte
return None


def plugin(version: str) -> Type[NewSemanalDRFPlugin]:
def plugin(version: str) -> type[NewSemanalDRFPlugin]:
return NewSemanalDRFPlugin
14 changes: 1 addition & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
[tool.black]
line-length = 120
include = '\.pyi?$'
target-version = ["py38", "py39", "py310", "py311", "py312"]

[tool.ruff]
# Adds to default excludes: https://docs.astral.sh/ruff/settings/#exclude
extend-exclude = [
".*/",
"drf_source",
"stubgen",
"out",
]
line-length = 120
target-version = "py38"
target-version = "py39"
# See Rules in Ruff documentation: https://docs.astral.sh/ruff/rules/
[tool.ruff.lint]
select = [
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
wheel
pre-commit==3.5.0; python_version < '3.9'
pre-commit==4.0.1; python_version >= '3.9'
pre-commit==4.0.1
pytest==8.3.4
pytest-mypy-plugins==3.1.2
djangorestframework==3.15.2
Expand Down
75 changes: 65 additions & 10 deletions rest_framework-stubs/test.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,26 @@ class APIRequestFactory(DjangoRequestFactory):
def __init__(self, enforce_csrf_checks: bool = ..., **defaults: Any) -> None: ...
def request(self, **kwargs: Any) -> Request: ... # type: ignore[override]
def get(self, path: str, data: _GetDataType = ..., **extra: Any) -> Request: ... # type: ignore[override]
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any) -> Request: ... # type: ignore[override]
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any) -> Request: ... # type: ignore[override]
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any) -> Request: ... # type: ignore[override]
def delete(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any) -> Request: ... # type: ignore[override]
def options(self, path: str, data: dict[str, str] | str | None = ..., format: str | None = ..., content_type: Any | None = ..., **extra: Any) -> Request: ... # type: ignore[override]
def post( # type: ignore[override]
self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any
) -> Request: ...
def put( # type: ignore[override]
self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any
) -> Request: ...
def patch( # type: ignore[override]
self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any
) -> Request: ...
def delete( # type: ignore[override]
self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., **extra: Any
) -> Request: ...
def options( # type: ignore[override]
self,
path: str,
data: dict[str, str] | str | None = ...,
format: str | None = ...,
content_type: Any | None = ...,
**extra: Any,
) -> Request: ...
def generic( # type: ignore[override]
self, method: str, path: str, data: str = ..., content_type: str = ..., secure: bool = ..., **extra: Any
) -> Request: ...
Expand All @@ -80,11 +95,51 @@ class APIClient(APIRequestFactory, DjangoClient):
) -> None: ...
def request(self, **kwargs: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def delete(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def options(self, path: str, data: dict[str, str] | str = ..., format: str | None = ..., content_type: Any | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def post( # type: ignore[override]
self,
path: str,
data: Any | None = ...,
format: str | None = ...,
content_type: str | None = ...,
follow: bool = ...,
**extra: Any,
) -> _MonkeyPatchedResponse: ...
def put( # type: ignore[override]
self,
path: str,
data: Any | None = ...,
format: str | None = ...,
content_type: str | None = ...,
follow: bool = ...,
**extra: Any,
) -> _MonkeyPatchedResponse: ...
def patch( # type: ignore[override]
self,
path: str,
data: Any | None = ...,
format: str | None = ...,
content_type: str | None = ...,
follow: bool = ...,
**extra: Any,
) -> _MonkeyPatchedResponse: ...
def delete( # type: ignore[override]
self,
path: str,
data: Any | None = ...,
format: str | None = ...,
content_type: str | None = ...,
follow: bool = ...,
**extra: Any,
) -> _MonkeyPatchedResponse: ...
def options( # type: ignore[override]
self,
path: str,
data: dict[str, str] | str = ...,
format: str | None = ...,
content_type: Any | None = ...,
follow: bool = ...,
**extra: Any,
) -> _MonkeyPatchedResponse: ...
def logout(self) -> None: ...

class APITransactionTestCase(testcases.TransactionTestCase):
Expand Down
4 changes: 2 additions & 2 deletions rest_framework-stubs/utils/field_mapping.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import Incomplete
from collections.abc import MutableMapping, Sequence
from typing import Any, Generic, Iterator, TypeVar
from collections.abc import Iterator, MutableMapping, Sequence
from typing import Any, Generic, TypeVar

from django.db import models
from rest_framework.validators import UniqueValidator
Expand Down
15 changes: 8 additions & 7 deletions rest_framework-stubs/utils/serializer_helpers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@ class ReturnDict(dict[_KT, _VT], Generic[_KT, _VT]):
@overload
def __init__(self: ReturnDict[str, _VT], *, serializer: BaseSerializer, **kwargs: _VT) -> None: ...
@overload
def __init__(self, __map: SupportsKeysAndGetItem[_KT, _VT], *, serializer: BaseSerializer) -> None: ...
def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], /, *, serializer: BaseSerializer) -> None: ...
@overload
def __init__(
self: ReturnDict[str, _VT],
__map: SupportsKeysAndGetItem[str, _VT],
map: SupportsKeysAndGetItem[str, _VT],
/,
*,
serializer: BaseSerializer,
**kwargs: _VT,
) -> None: ...
@overload
def __init__(self, __iterable: Iterable[tuple[_KT, _VT]], *, serializer: BaseSerializer) -> None: ...
def __init__(self, iterable: Iterable[tuple[_KT, _VT]], /, *, serializer: BaseSerializer) -> None: ...
@overload
def __init__(
self: ReturnDict[str, _VT], __iterable: Iterable[tuple[str, _VT]], *, serializer: BaseSerializer, **kwargs: _VT
self: ReturnDict[str, _VT], iterable: Iterable[tuple[str, _VT]], /, *, serializer: BaseSerializer, **kwargs: _VT
) -> None: ...
# Next two overloads are for dict(string.split(sep) for string in iterable)
# Cannot be Iterable[Sequence[_T]] or otherwise dict(["foo", "bar", "baz"]) is not an error
@overload
def __init__(
self: ReturnDict[str, str], __iterable: Iterable[list[str]], *, serializer: BaseSerializer
self: ReturnDict[str, str], iterable: Iterable[list[str]], /, *, serializer: BaseSerializer
) -> None: ...
@overload
def __init__(
self: ReturnDict[bytes, bytes], __iterable: Iterable[list[bytes]], *, serializer: BaseSerializer
self: ReturnDict[bytes, bytes], iterable: Iterable[list[bytes]], /, *, serializer: BaseSerializer
) -> None: ...
def copy(self) -> ReturnDict[_KT, _VT]: ...
def __reduce__(self) -> tuple[type[dict[_KT, _VT]], tuple[dict[_KT, _VT]]]: ...
Expand All @@ -52,7 +53,7 @@ class ReturnList(list[_T], Generic[_T]):
@overload
def __init__(self, *, serializer: BaseSerializer) -> None: ...
@overload
def __init__(self, __iterable: Iterable[_T], *, serializer: BaseSerializer) -> None: ...
def __init__(self, iterable: Iterable[_T], /, *, serializer: BaseSerializer) -> None: ...
def __reduce__(self) -> tuple[type[list[_T]], tuple[list[_T]]]: ...

class BoundField:
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _V = TypeVar("_V", contravariant=True)

class ContextValidator(Protocol[_V]):
requires_context: bool
def __call__(self, __value: _V, __context: Field) -> None: ...
def __call__(self, value: _V, context: Field, /) -> None: ...

Validator: TypeAlias = Callable[[_V], None] | ContextValidator[_V]

Expand Down
1 change: 1 addition & 0 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ rest_framework.serializers.empty
rest_framework.settings.DefaultsSettings
rest_framework.settings.api_settings
rest_framework.templatetags.rest_framework.urlize_quoted_links
rest_framework.test.CoreAPIClient
rest_framework.test.APIClient.options
rest_framework.test.RequestsClient.__init__
rest_framework.throttling.SimpleRateThrottle.cache
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
from typing import List

from setuptools import find_packages, setup


def find_stub_files(name: str) -> List[str]:
def find_stub_files(name: str) -> list[str]:
result = []
for root, _dirs, files in os.walk(name):
for file in files:
Expand Down Expand Up @@ -50,15 +49,15 @@ def find_stub_files(name: str) -> List[str]:
extras_require=extras_require,
packages=["rest_framework-stubs", *find_packages(exclude=["scripts"])],
package_data={"rest_framework-stubs": find_stub_files("rest_framework-stubs")},
python_requires=">=3.8",
python_requires=">=3.9",
classifiers=[
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
"Framework :: Django",
],
Expand Down

0 comments on commit 4b38801

Please sign in to comment.