Skip to content

Commit b51d616

Browse files
authored
Merge branch 'master' into fix-cleanup-serializer-typevars
2 parents dfbff86 + 3b185d3 commit b51d616

File tree

18 files changed

+84
-40
lines changed

18 files changed

+84
-40
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
15+
cancel-in-progress: true
16+
1017
jobs:
1118
mypy-self-check:
1219
timeout-minutes: 10
1320
runs-on: ubuntu-latest
1421
strategy:
22+
fail-fast: false
1523
matrix:
1624
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
1725
steps:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ repos:
1313
- id: check-merge-conflict
1414
- id: end-of-file-fixer
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.1.6
16+
rev: v0.3.3
1717
hooks:
1818
- id: ruff
1919
args: ["--fix", "--exit-non-zero-on-fix"]
2020
- repo: https://github.com/psf/black
21-
rev: 23.11.0
21+
rev: 24.3.0
2222
hooks:
2323
- id: black
2424

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[tool.black]
22
line-length = 120
33
include = '\.pyi?$'
4+
target-version = ["py38", "py39", "py310", "py311", "py312"]
45

56
[tool.ruff]
67
# Adds to default excludes: https://docs.astral.sh/ruff/settings/#exclude
@@ -39,10 +40,9 @@ ignore = ["PYI021", "PYI024", "PYI041", "PYI043"]
3940
"F405",
4041
"F822",
4142
"F821",
42-
"PYI026", # TODO fix these errors
4343
"PGH003", # TODO fix these errors
44-
"PYI002", # TODO fix these errors
4544
]
45+
"rest_framework-stubs/compat.pyi" = ["PYI042"]
4646

4747
[tool.ruff.flake8-tidy-imports.banned-api]
4848
"_typeshed.Self".msg = "Use typing_extensions.Self (PEP 673) instead."

requirements.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
wheel
2-
pre-commit==3.5.0
3-
pytest==7.4.3
4-
pytest-mypy-plugins==3.0.0
5-
djangorestframework==3.14.0
6-
types-pytz==2023.3.1.1
7-
types-requests==2.31.0.10
2+
pre-commit==3.5.0; python_version < '3.9'
3+
pre-commit==3.6.2; python_version >= '3.9'
4+
pytest==8.1.1
5+
pytest-mypy-plugins==3.1.1
6+
djangorestframework==3.15.0
7+
types-pytz==2024.1.0.20240203
8+
types-requests==2.31.0.20240311
89
types-urllib3==1.26.25.14
910
django-stubs[compatible-mypy] @ git+https://github.com/typeddjango/django-stubs
1011
django-stubs-ext @ git+https://github.com/typeddjango/django-stubs#subdirectory=ext

rest_framework-stubs/compat.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
from typing import Any
22

33
from django.db.models import QuerySet
4+
from typing_extensions import TypeAlias
45

56
try:
67
from django.contrib.postgres import fields as postgres_fields
78
except ImportError:
8-
postgres_fields = None # type: ignore
9+
postgres_fields: TypeAlias = None # type: ignore[no-redef]
910
try:
1011
import coreapi
1112
except ImportError:
12-
coreapi = None
13+
coreapi: TypeAlias = None # type: ignore[no-redef]
1314
try:
1415
import uritemplate
1516
except ImportError:
16-
uritemplate = None # type: ignore
17+
uritemplate: TypeAlias = None # type: ignore[no-redef]
1718
try:
1819
import coreschema
1920
except ImportError:
20-
coreschema = None
21+
coreschema: TypeAlias = None # type: ignore[no-redef]
2122
try:
2223
import yaml
2324
except ImportError:
24-
yaml = None # type: ignore
25+
yaml: TypeAlias = None # type: ignore[no-redef]
2526
try:
2627
import requests
2728
except ImportError:
28-
requests = None # type: ignore
29+
requests: TypeAlias = None # type: ignore[no-redef]
2930
try:
3031
import pygments
3132
except ImportError:
32-
pygments = None
33+
pygments: TypeAlias = None # type: ignore[no-redef]
34+
3335
try:
3436
import markdown
35-
def apply_markdown(text: str) -> str: ...
36-
37-
except ImportError:
38-
apply_markdown = None # type: ignore
39-
markdown = None # type: ignore
40-
41-
if markdown is not None and pygments is not None:
4237
from markdown.preprocessors import Preprocessor
38+
def apply_markdown(text: str) -> str: ...
4339

4440
class CodeBlockPreprocessor(Preprocessor):
4541
pattern: Any
4642
formatter: Any
4743
def run(self, lines: list[str]) -> list[str]: ...
4844

45+
except ImportError:
46+
apply_markdown: TypeAlias = None # type: ignore[no-redef]
47+
markdown: TypeAlias = None # type: ignore[no-redef]
48+
4949
def pygments_css(style: Any) -> str | None: ...
5050
def pygments_highlight(text: str, lang: str, style: Any) -> Any: ...
5151
def md_filter_add_syntax_highlight(md: Any) -> bool: ...

rest_framework-stubs/exceptions.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Mapping, Sequence
2-
from typing import Any
2+
from typing import Any, ClassVar
33

44
from django.http import HttpRequest, JsonResponse
55
from django_stubs_ext import StrOrPromise
@@ -43,6 +43,10 @@ class APIException(Exception):
4343
class ValidationError(APIException):
4444
# ValidationError wraps `detail` in a list if it's not already a list/dict.
4545
detail: list[_Detail] | dict[str, _Detail]
46+
default_params: ClassVar[Mapping[str, Any]]
47+
def __init__(
48+
self, detail: _Detail | None = ..., code: str | None = ..., params: Mapping[str, Any] | None = ...
49+
) -> None: ...
4650

4751
class ParseError(APIException): ...
4852
class AuthenticationFailed(APIException): ...

rest_framework-stubs/fields.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class EmailField(CharField): ...
181181
class RegexField(CharField):
182182
def __init__(
183183
self,
184-
regex: str | Pattern,
184+
regex: str | Pattern[str],
185185
*,
186186
read_only: bool = ...,
187187
write_only: bool = ...,

rest_framework-stubs/renderers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BrowsableAPIRenderer(BaseRenderer):
6565
view_instance: APIView,
6666
request: Request,
6767
*args: Incomplete,
68-
**kwargs: Incomplete
68+
**kwargs: Incomplete,
6969
) -> BaseSerializer: ...
7070
def get_rendered_html_form(self, data: Any, view: APIView, method: str, request: Request) -> Any: ...
7171
def render_form_for_serializer(self, serializer: BaseSerializer) -> Any: ...

rest_framework-stubs/reverse.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ def reverse(
1010
kwargs: Mapping[str, Any] | None = ...,
1111
request: HttpRequest | None = ...,
1212
format: str | None = ...,
13-
**extra: Any
13+
**extra: Any,
1414
) -> str: ...
1515
def _reverse(
1616
viewname: str,
1717
args: Sequence[Any] | None = ...,
1818
kwargs: Mapping[str, Any] | None = ...,
1919
request: HttpRequest | None = ...,
2020
format: str | None = ...,
21-
**extra: Any
21+
**extra: Any,
2222
) -> str: ...
2323

2424
reverse_lazy: Callable[..., str]

rest_framework-stubs/routers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BaseRouter(metaclass=RenameRouterMethods):
4343
class SimpleRouter(BaseRouter):
4444
routes: list[Route | DynamicRoute]
4545
trailing_slash: str
46-
def __init__(self, trailing_slash: bool = ...) -> None: ...
46+
def __init__(self, trailing_slash: bool = ..., use_regex_path: bool = ...) -> None: ...
4747
def get_routes(self, viewset: type[ViewSetMixin]) -> list[Route]: ...
4848
def _get_dynamic_route(self, route: DynamicRoute, action: Any) -> Route: ...
4949
def get_method_map(self, viewset: type[ViewSetMixin], method_map: Mapping[str, str]) -> dict[str, str]: ...

0 commit comments

Comments
 (0)