Skip to content

Commit adf6975

Browse files
authored
Harmonize mypy.ini config with django-stubs (#479)
* Most of the overrides in `tests/plugins.ini` are no longer needed * Removed lots of unneeded `# type: ignore` comments * Will create a separate PR to update `disallow_untyped_defs` and `disallow_incomplete_defs` too
1 parent fc62c8e commit adf6975

File tree

9 files changed

+34
-49
lines changed

9 files changed

+34
-49
lines changed

mypy.ini

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
[mypy]
2-
strict_optional = true
3-
ignore_missing_imports = true
4-
check_untyped_defs = true
5-
show_traceback = true
62
allow_redefinition = true
3+
check_untyped_defs = true
4+
ignore_missing_imports = true
75
incremental = true
6+
strict_optional = true
7+
show_traceback = true
8+
warn_unused_ignores = true
9+
warn_redundant_casts = true
10+
warn_unused_configs = true
11+
warn_unreachable = true
12+
# TODO: enable disallow_*_defs later
13+
disallow_untyped_defs = false
14+
disallow_incomplete_defs = false
815
disable_error_code = empty-body
916
# TODO: update our test error messages to match new mypy output
1017
show_error_codes = false
@@ -17,3 +24,6 @@ plugins =
1724

1825
[mypy.plugins.django-stubs]
1926
django_settings_module = scripts.drf_tests_settings
27+
28+
[mypy-uritemplate.*]
29+
warn_unreachable = false

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ addopts =
66
-s
77
-v
88
--cache-clear
9-
--mypy-ini-file=./tests/plugins.ini
9+
--mypy-ini-file=mypy.ini
1010
--mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook

rest_framework-stubs/compat.pyi

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ except ImportError:
1010
try:
1111
import coreapi
1212
except ImportError:
13-
coreapi = None # type: ignore
13+
coreapi = None
1414
try:
1515
import uritemplate
1616
except ImportError:
1717
uritemplate = None # type: ignore
1818
try:
1919
import coreschema
2020
except ImportError:
21-
coreschema = None # type: ignore
21+
coreschema = None
2222
try:
2323
import yaml
2424
except ImportError:
@@ -30,17 +30,17 @@ except ImportError:
3030
try:
3131
import pygments
3232
except ImportError:
33-
pygments = None # type: ignore
33+
pygments = None
3434
try:
35-
import markdown # type: ignore
35+
import markdown
3636
def apply_markdown(text: str): ...
3737

3838
except ImportError:
3939
apply_markdown = None # type: ignore
4040
markdown = None # type: ignore
4141

4242
if markdown is not None and pygments is not None:
43-
from markdown.preprocessors import Preprocessor # type: ignore
43+
from markdown.preprocessors import Preprocessor
4444

4545
class CodeBlockPreprocessor(Preprocessor):
4646
pattern: Any

rest_framework-stubs/permissions.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class OR(_SupportsHasPermission):
4646
class NOT(_SupportsHasPermission):
4747
def __init__(self, op1: _SupportsHasPermission) -> None: ...
4848

49-
class BasePermissionMetaclass(OperationHolderMixin, type): ... # type: ignore[misc]
49+
class BasePermissionMetaclass(OperationHolderMixin, type): ... # type: ignore[misc,unused-ignore]
5050

51-
class BasePermission(metaclass=BasePermissionMetaclass): # type: ignore[misc]
51+
class BasePermission(metaclass=BasePermissionMetaclass):
5252
def has_permission(self, request: Request, view: APIView) -> bool: ...
5353
def has_object_permission(self, request: Request, view: APIView, obj: Any) -> bool: ...
5454

rest_framework-stubs/relations.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class RelatedField(Generic[_MT, _DT, _PT], Field[_MT, _DT, _PT, Any]):
6767
@property
6868
def grouped_choices(self) -> dict: ...
6969
def iter_options(self) -> Iterable[Option]: ...
70-
def get_attribute(self, instance: _MT) -> _PT | None: ... # type: ignore[override]
70+
def get_attribute(self, instance: _MT) -> _PT | None: ...
7171
def display_value(self, instance: _MT) -> str: ...
7272

7373
class StringRelatedField(RelatedField[_MT, _MT, str]): ...
@@ -180,7 +180,7 @@ class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]):
180180
allow_empty: bool = ...,
181181
child_relation: RelatedField = ...,
182182
): ...
183-
def get_value(self, dictionary: Mapping[Any, Any]) -> list[Any]: ... # type: ignore[override]
183+
def get_value(self, dictionary: Mapping[Any, Any]) -> list[Any]: ...
184184
def get_choices(self, cutoff: int | None = ...) -> dict: ...
185185
@property
186186
def choices(self) -> dict: ...

rest_framework-stubs/request.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class Request(HttpRequest):
6565
def query_params(self) -> _ImmutableQueryDict: ...
6666
@property
6767
def data(self) -> dict[str, Any]: ...
68-
@property # type: ignore[override]
69-
def user(self) -> AbstractBaseUser | AnonymousUser: ... # type: ignore[override]
68+
@property
69+
def user(self) -> AbstractBaseUser | AnonymousUser: ...
7070
@user.setter
7171
def user(self, value: AbstractBaseUser | AnonymousUser) -> None: ...
7272
@property

rest_framework-stubs/serializers.pyi

+7-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class BaseSerializer(Generic[_IN], Field[Any, Any, Any, _IN]):
111111
def update(self, instance: _IN, validated_data: Any) -> _IN: ...
112112
def create(self, validated_data: Any) -> _IN: ...
113113
def save(self, **kwargs: Any) -> _IN: ...
114-
def to_representation(self, instance: _IN) -> Any: ... # type: ignore[override]
114+
def to_representation(self, instance: _IN) -> Any: ...
115115

116116
class SerializerMetaclass(type):
117117
def __new__(cls, name: Any, bases: Any, attrs: Any): ...
@@ -189,15 +189,15 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]):
189189
serializer_url_field: type[RelatedField]
190190
serializer_choice_field: type[Field]
191191
url_field_name: str | None
192-
instance: _MT | Sequence[_MT] | None # type: ignore[override]
192+
instance: _MT | Sequence[_MT] | None
193193

194194
class Meta:
195195
model: type[_MT] # type: ignore
196196
fields: Sequence[str] | Literal["__all__"]
197197
read_only_fields: Sequence[str] | None
198198
exclude: Sequence[str] | None
199199
depth: int | None
200-
extra_kwargs: dict[str, dict[str, Any]] # type: ignore[override]
200+
extra_kwargs: dict[str, dict[str, Any]]
201201
def __init__(
202202
self,
203203
instance: None | _MT | Sequence[_MT] | QuerySet[_MT] | Manager[_MT] = ...,
@@ -219,10 +219,10 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]):
219219
allow_null: bool = ...,
220220
allow_empty: bool = ...,
221221
): ...
222-
def update(self, instance: _MT, validated_data: Any) -> _MT: ... # type: ignore[override]
223-
def create(self, validated_data: Any) -> _MT: ... # type: ignore[override]
224-
def save(self, **kwargs: Any) -> _MT: ... # type: ignore[override]
225-
def to_representation(self, instance: _MT) -> Any: ... # type: ignore[override]
222+
def update(self, instance: _MT, validated_data: Any) -> _MT: ...
223+
def create(self, validated_data: Any) -> _MT: ...
224+
def save(self, **kwargs: Any) -> _MT: ...
225+
def to_representation(self, instance: _MT) -> Any: ...
226226
def get_field_names(self, declared_fields: Mapping[str, Field], info: FieldInfo) -> list[str]: ...
227227
def get_default_field_names(self, declared_fields: Mapping[str, Field], model_info: FieldInfo) -> list[str]: ...
228228
def build_field(

rest_framework-stubs/views.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ class APIView(View):
8888
def finalize_response(self, request: Request, response: Response, *args: Any, **kwargs: Any) -> Response: ...
8989
def handle_exception(self, exc: Exception) -> Response: ...
9090
def raise_uncaught_exception(self, exc: Exception) -> NoReturn: ...
91-
def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponseBase: ... # type: ignore[override]
91+
def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponseBase: ...
9292
def options(self, request: Request, *args: Any, **kwargs: Any): ... # type: ignore[override]

tests/plugins.ini

-25
This file was deleted.

0 commit comments

Comments
 (0)