Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to mypy 0.991 for compatible-mypy & CI #280

Merged
merged 2 commits into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy.ini
Expand Up @@ -2,10 +2,11 @@
strict_optional = True
ignore_missing_imports = True
check_untyped_defs = True
warn_no_return = False
show_traceback = True
allow_redefinition = True
incremental = True
show_error_codes = False
disable_error_code = empty-body
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warn_no_return is no longer necessary now that we disable empty-body.


plugins =
mypy_django_plugin.main,
Expand Down
6 changes: 5 additions & 1 deletion rest_framework-stubs/permissions.pyi
Expand Up @@ -44,7 +44,11 @@ class NOT(_SupportsHasPermission):
def __init__(self, op1: _SupportsHasPermission) -> None: ...

class BasePermissionMetaclass(OperationHolderMixin, type): ... # type: ignore[misc]
class BasePermission(_SupportsHasPermission, metaclass=BasePermissionMetaclass): ... # type: ignore[misc]

class BasePermission(metaclass=BasePermissionMetaclass): # type: ignore[misc]
def has_permission(self, request: Request, view: APIView) -> bool: ...
def has_object_permission(self, request: Request, view: APIView, obj: Any) -> bool: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I kept _SupportsHasPermission here, it causes "Metaclass conflict" errors.

I don't understand metaclasses well enough to say whether that's a bug in mypy or a genuine issue.

But duplicating these method signatures here fixes it.


class AllowAny(BasePermission): ...
class IsAuthenticated(BasePermission): ...
class IsAdminUser(BasePermission): ...
Expand Down
6 changes: 5 additions & 1 deletion scripts/typecheck_tests.py
Expand Up @@ -60,6 +60,9 @@
'"BaseTokenAuthTests" has no attribute "assertNumQueries"',
'Module "django.middleware.csrf" has no attribute "_mask_cipher_secret"',
"All conditional function variants must have identical signatures",
"note: def _get_new_csrf_token() ->",
"note: Original:",
"note: Redefinition:",
],
"schemas": [
'(expression has type "CharField", base class "Field" defined the type as "bool")',
Expand All @@ -77,6 +80,7 @@
'Argument "patterns" to "SchemaGenerator" has incompatible type "List[object]"',
'Argument 1 to "field_to_schema" has incompatible type "object"; expected "Field[Any, Any, Any, Any]"',
'Argument "help_text" to "CharField" has incompatible type "_StrPromise"',
'"Module rest_framework.schemas.coreapi" does not explicitly export attribute "coreapi"',
],
"browsable_api": [
'(expression has type "List[Dict[str, Dict[str, int]]]", base class "GenericAPIView" defined the type as "Union[QuerySet[_MT?], Manager[_MT?], None]")', # noqa: E501
Expand Down Expand Up @@ -114,7 +118,7 @@
'Argument "params" to "ValidationError" has incompatible type "Tuple[str]"',
'"MultipleChoiceField[Model]" has no attribute "partial"',
'Argument 1 to "to_internal_value" of "Field" has incompatible type "Dict[str, str]"; expected "List[Any]"',
'Module "rest_framework.fields" has no attribute "DjangoImageField"; maybe "ImageField"?',
'Module "rest_framework.fields" does not explicitly export attribute "DjangoImageField"',
'Argument 1 to "ListField" has incompatible type "CharField"; expected "bool"',
"Possible overload variants:",
"def __init__(self, *, mutable: Literal[True], query_string: Union[str, bytes, None] = ..., encoding: Optional[str] = ...) -> QueryDict", # noqa: E501
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@ def find_stub_files(name):
]

extras_require = {
"compatible-mypy": ["mypy>=0.980,<0.990"],
"compatible-mypy": ["mypy>=0.991,<0.1000"],
"coreapi": ["coreapi>=2.0.0"],
"markdown": ["types-Markdown>=0.1.5"],
}
Expand Down
2 changes: 2 additions & 0 deletions tests/plugins.ini
@@ -1,5 +1,7 @@
[mypy]
check_untyped_defs = True
show_error_codes = False
disable_error_code = empty-body
plugins =
mypy_django_plugin.main,
mypy_drf_plugin.main
Expand Down