From 8f2dccb19851302fc0992d456e7e43f3e89e6820 Mon Sep 17 00:00:00 2001 From: Karataev Pavel Date: Fri, 30 Aug 2024 03:59:18 +0300 Subject: [PATCH] Add a bunch of 'pyright: ignore' for django-stubs/ --- .../contrib/admin/templatetags/base.pyi | 2 +- django-stubs/contrib/contenttypes/fields.pyi | 2 +- django-stubs/contrib/contenttypes/models.pyi | 4 +- django-stubs/core/files/base.pyi | 2 +- django-stubs/core/mail/message.pyi | 12 +++--- django-stubs/core/serializers/json.pyi | 2 +- django-stubs/core/servers/basehttp.pyi | 4 +- django-stubs/db/models/fields/files.pyi | 4 +- django-stubs/db/models/fields/related.pyi | 40 +++++++++++++------ .../db/models/fields/related_descriptors.pyi | 6 +-- django-stubs/http/cookie.pyi | 2 +- django-stubs/http/response.pyi | 2 +- django-stubs/template/context.pyi | 4 +- django-stubs/template/response.pyi | 6 +-- django-stubs/test/client.pyi | 2 +- django-stubs/utils/log.pyi | 2 +- django-stubs/utils/six.pyi | 2 +- django-stubs/views/decorators/csrf.pyi | 2 +- 18 files changed, 59 insertions(+), 41 deletions(-) diff --git a/django-stubs/contrib/admin/templatetags/base.pyi b/django-stubs/contrib/admin/templatetags/base.pyi index ca38fe4cf..ea10ef436 100644 --- a/django-stubs/contrib/admin/templatetags/base.pyi +++ b/django-stubs/contrib/admin/templatetags/base.pyi @@ -10,7 +10,7 @@ class InclusionAdminNode(InclusionNode): args: list[Any] func: Callable[..., Any] kwargs: dict[Any, Any] - takes_context: bool + takes_context: bool # pyright: ignore[reportIncompatibleVariableOverride] template_name: str = ... def __init__( self, diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi index ea6b5565a..33a5102cb 100644 --- a/django-stubs/contrib/contenttypes/fields.pyi +++ b/django-stubs/contrib/contenttypes/fields.pyi @@ -67,7 +67,7 @@ class GenericForeignKey(FieldCacheMixin): def __set__(self, instance: Model, value: Any | None) -> None: ... class GenericRel(ForeignObjectRel): - field: GenericRelation + field: GenericRelation # pyright: ignore[reportIncompatibleVariableOverride] def __init__( self, field: GenericRelation, diff --git a/django-stubs/contrib/contenttypes/models.pyi b/django-stubs/contrib/contenttypes/models.pyi index 69af4dadb..289b7ccf7 100644 --- a/django-stubs/contrib/contenttypes/models.pyi +++ b/django-stubs/contrib/contenttypes/models.pyi @@ -22,7 +22,9 @@ class ContentType(models.Model): id: int app_label: models.CharField[Any] = ... model: models.CharField[Any] = ... - objects: ClassVar[ContentTypeManager] = ... + objects: ClassVar[ # pyright: ignore[reportIncompatibleVariableOverride] + ContentTypeManager + ] = ... permission_set: Manager[Permission] @property def name(self) -> str: ... diff --git a/django-stubs/core/files/base.pyi b/django-stubs/core/files/base.pyi index 91f2632f3..632e6d0dd 100644 --- a/django-stubs/core/files/base.pyi +++ b/django-stubs/core/files/base.pyi @@ -31,7 +31,7 @@ class File(FileProxyMixin, IO[Any]): def close(self) -> None: ... class ContentFile(File): - file: StringIO + file: StringIO # pyright: ignore[reportIncompatibleVariableOverride] size: Any = ... def __init__(self, content: bytes | str, name: str | None = ...) -> None: ... def write(self, data: str) -> int: ... # type: ignore[override] diff --git a/django-stubs/core/mail/message.pyi b/django-stubs/core/mail/message.pyi index a2ae5708c..4554a8031 100644 --- a/django-stubs/core/mail/message.pyi +++ b/django-stubs/core/mail/message.pyi @@ -26,15 +26,15 @@ class MIMEMixin: ... class SafeMIMEMessage(MIMEMixin, MIMEMessage): defects: list[Any] - epilogue: None + epilogue: None # pyright: ignore[reportIncompatibleVariableOverride] policy: Policy # type: ignore [no-any-unimported] - preamble: None + preamble: None # pyright: ignore[reportIncompatibleVariableOverride] class SafeMIMEText(MIMEMixin, MIMEText): defects: list[Any] - epilogue: None + epilogue: None # pyright: ignore[reportIncompatibleVariableOverride] policy: Policy # type: ignore [no-any-unimported] - preamble: None + preamble: None # pyright: ignore[reportIncompatibleVariableOverride] encoding: str = ... def __init__( self, _text: str, _subtype: str = ..., _charset: str = ... @@ -42,9 +42,9 @@ class SafeMIMEText(MIMEMixin, MIMEText): class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): defects: list[Any] - epilogue: None + epilogue: None # pyright: ignore[reportIncompatibleVariableOverride] policy: Policy # type: ignore [no-any-unimported] - preamble: None + preamble: None # pyright: ignore[reportIncompatibleVariableOverride] encoding: str = ... def __init__( self, diff --git a/django-stubs/core/serializers/json.pyi b/django-stubs/core/serializers/json.pyi index 17bd23547..56fd5bb82 100644 --- a/django-stubs/core/serializers/json.pyi +++ b/django-stubs/core/serializers/json.pyi @@ -12,6 +12,6 @@ class DjangoJSONEncoder(json.JSONEncoder): allow_nan: bool check_circular: bool ensure_ascii: bool - indent: int + indent: int # pyright: ignore[reportIncompatibleVariableOverride] skipkeys: bool sort_keys: bool diff --git a/django-stubs/core/servers/basehttp.pyi b/django-stubs/core/servers/basehttp.pyi index f659f0d58..b6f03ee6b 100644 --- a/django-stubs/core/servers/basehttp.pyi +++ b/django-stubs/core/servers/basehttp.pyi @@ -28,8 +28,8 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler): close_connection: bool connection: WSGIRequest request: WSGIRequest - rfile: BytesIO - wfile: BytesIO + rfile: BytesIO # pyright: ignore[reportIncompatibleVariableOverride] + wfile: BytesIO # pyright: ignore[reportIncompatibleVariableOverride] protocol_version: str = ... def address_string(self) -> str: ... def log_message(self, format: str, *args: Any) -> None: ... diff --git a/django-stubs/db/models/fields/files.pyi b/django-stubs/db/models/fields/files.pyi index af93c1f78..d28d763c9 100644 --- a/django-stubs/db/models/fields/files.pyi +++ b/django-stubs/db/models/fields/files.pyi @@ -81,11 +81,11 @@ class FileField(Field[FileDescriptor, FileDescriptor]): def generate_filename(self, instance: Model | None, filename: str) -> str: ... class ImageFileDescriptor(FileDescriptor): - field: ImageField + field: ImageField # pyright: ignore[reportIncompatibleVariableOverride] def __set__(self, instance: Model, value: str | None) -> None: ... class ImageFieldFile(ImageFile, FieldFile): - field: ImageField + field: ImageField # pyright: ignore[reportIncompatibleVariableOverride] def delete(self, save: bool = ...) -> None: ... class ImageField(FileField): diff --git a/django-stubs/db/models/fields/related.pyi b/django-stubs/db/models/fields/related.pyi index 758ef63ec..d214ac09a 100644 --- a/django-stubs/db/models/fields/related.pyi +++ b/django-stubs/db/models/fields/related.pyi @@ -54,10 +54,10 @@ _ErrorMessagesToOverride = dict[str, Any] RECURSIVE_RELATIONSHIP_CONSTANT: str = ... class RelatedField(FieldCacheMixin, Generic[_ST, _GT], Field[_ST, _GT]): - one_to_many: bool = ... - one_to_one: bool = ... - many_to_many: bool = ... - many_to_one: bool = ... + one_to_many: bool = ... # pyright: ignore[reportIncompatibleVariableOverride] + one_to_one: bool = ... # pyright: ignore[reportIncompatibleVariableOverride] + many_to_many: bool = ... # pyright: ignore[reportIncompatibleVariableOverride] + many_to_one: bool = ... # pyright: ignore[reportIncompatibleVariableOverride] related_model: type[_GT] = ... opts: Any = ... def get_forward_related_filter(self, obj: Model) -> dict[str, int | UUID]: ... @@ -74,10 +74,18 @@ class RelatedField(FieldCacheMixin, Generic[_ST, _GT], Field[_ST, _GT]): _M = TypeVar("_M", bound=Model | None) class ForeignObject(Generic[_M], RelatedField[_M, _M]): - one_to_many: Literal[False] = ... - one_to_one: Literal[False] = ... - many_to_many: Literal[False] = ... - many_to_one: Literal[True] = ... + one_to_many: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + False + ] = ... + one_to_one: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + False + ] = ... + many_to_many: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + False + ] = ... + many_to_one: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + True + ] = ... related_model: type[_M] = ... @overload def __new__( @@ -332,10 +340,18 @@ _MN = TypeVar("_MN", bound=Model) class ManyToManyField( Generic[_MM, _MN], RelatedField[Sequence[_MN], ManyToManyRelatedManager[_MM, _MN]] ): - one_to_many: Literal[False] = ... - one_to_one: Literal[False] = ... - many_to_many: Literal[True] = ... - many_to_one: Literal[False] = ... + one_to_many: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + False + ] = ... + one_to_one: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + False + ] = ... + many_to_many: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + True + ] = ... + many_to_one: Literal[ # pyright: ignore[reportIncompatibleVariableOverride] + False + ] = ... rel_class: Any = ... description: Any = ... has_null_arg: Any = ... diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index bbc9d8bb4..e3dcdddce 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -31,7 +31,7 @@ class ForwardManyToOneDescriptor: class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor): RelatedObjectDoesNotExist: type[ObjectDoesNotExist] - field: OneToOneField[Any] + field: OneToOneField[Any] # pyright: ignore[reportIncompatibleVariableOverride] def get_object(self, instance: Model) -> Model: ... class ReverseOneToOneDescriptor: @@ -64,8 +64,8 @@ class ReverseManyToOneDescriptor: def create_reverse_many_to_one_manager(superclass: Any, rel: Any) -> Any: ... class ManyToManyDescriptor(ReverseManyToOneDescriptor): - field: RelatedField[Any, Any] - rel: ManyToManyRel + field: RelatedField[Any, Any] # pyright: ignore[reportIncompatibleVariableOverride] + rel: ManyToManyRel # pyright: ignore[reportIncompatibleVariableOverride] reverse: bool = ... def __init__(self, rel: ManyToManyRel, reverse: bool = ...) -> None: ... @property diff --git a/django-stubs/http/cookie.pyi b/django-stubs/http/cookie.pyi index 2f9214ac0..32bd0b02e 100644 --- a/django-stubs/http/cookie.pyi +++ b/django-stubs/http/cookie.pyi @@ -1,5 +1,5 @@ from http import cookies -SimpleCookie = cookies.SimpleCookie[str] +SimpleCookie = cookies.SimpleCookie def parse_cookie(cookie: str) -> dict[str, str]: ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi index 6ae141546..6c45bcca1 100644 --- a/django-stubs/http/response.pyi +++ b/django-stubs/http/response.pyi @@ -19,7 +19,7 @@ class ResponseHeaders(CaseInsensitiveMapping[str]): class BadHeaderError(ValueError): ... class HttpResponseBase: - cookies: SimpleCookie + cookies: SimpleCookie # type: ignore [type-arg] headers: ResponseHeaders status_code: int closed: bool diff --git a/django-stubs/template/context.pyi b/django-stubs/template/context.pyi index 9f5466d2f..7b25f73fd 100644 --- a/django-stubs/template/context.pyi +++ b/django-stubs/template/context.pyi @@ -68,8 +68,8 @@ class RequestContext(Context): dicts: list[dict[str, str]] render_context: RenderContext template_name: str | None - use_l10n: None - use_tz: None + use_l10n: None # pyright: ignore[reportIncompatibleVariableOverride] + use_tz: None # pyright: ignore[reportIncompatibleVariableOverride] request: HttpRequest = ... def __init__( self, diff --git a/django-stubs/template/response.pyi b/django-stubs/template/response.pyi index 750640adf..86dfa9b7c 100644 --- a/django-stubs/template/response.pyi +++ b/django-stubs/template/response.pyi @@ -15,7 +15,7 @@ class ContentNotRenderedError(Exception): ... class SimpleTemplateResponse(HttpResponse): content: Any = ... closed: bool - cookies: SimpleCookie[Any] + cookies: SimpleCookie # type: ignore [type-arg] status_code: int rendering_attrs: Any = ... template_name: list[str] | Template | str = ... @@ -47,9 +47,9 @@ class SimpleTemplateResponse(HttpResponse): class TemplateResponse(SimpleTemplateResponse): client: Client closed: bool - context: RequestContext + context: RequestContext # pyright: ignore[reportIncompatibleVariableOverride] context_data: dict[str, Any] | None - cookies: SimpleCookie[Any] + cookies: SimpleCookie # type: ignore [type-arg] csrf_cookie_set: bool json: functools.partial[Any] redirect_chain: list[tuple[str, int]] diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index 279523c94..76bdc685b 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -52,7 +52,7 @@ _RequestData = Any | None class RequestFactory: json_encoder: type[JSONEncoder] defaults: dict[str, str] - cookies: SimpleCookie + cookies: SimpleCookie # type: ignore [type-arg] errors: BytesIO def __init__( self, diff --git a/django-stubs/utils/log.pyi b/django-stubs/utils/log.pyi index 61c0bf711..c5efafb60 100644 --- a/django-stubs/utils/log.pyi +++ b/django-stubs/utils/log.pyi @@ -36,7 +36,7 @@ class RequireDebugTrue(logging.Filter): def filter(self, record: str | LogRecord) -> bool: ... class ServerFormatter(logging.Formatter): - datefmt: None + datefmt: None # pyright: ignore[reportIncompatibleVariableOverride] style: Style = ... def __init__(self, *args: Any, **kwargs: Any) -> None: ... def uses_server_time(self) -> bool: ... diff --git a/django-stubs/utils/six.pyi b/django-stubs/utils/six.pyi index 381d068ce..e6b386279 100644 --- a/django-stubs/utils/six.pyi +++ b/django-stubs/utils/six.pyi @@ -43,7 +43,7 @@ def get_method_function(meth: types.MethodType) -> types.FunctionType: ... def get_method_self(meth: types.MethodType) -> object | None: ... def get_function_closure( fun: types.FunctionType, -) -> tuple[types._Cell, ...] | None: ... +) -> tuple[types._Cell, ...] | None: ... # pyright: ignore[reportAttributeAccessIssue] def get_function_code(fun: types.FunctionType) -> types.CodeType: ... def get_function_defaults(fun: types.FunctionType) -> tuple[Any, ...] | None: ... def get_function_globals(fun: types.FunctionType) -> dict[str, Any]: ... diff --git a/django-stubs/views/decorators/csrf.pyi b/django-stubs/views/decorators/csrf.pyi index a7b2f5fc1..32d5dcd26 100644 --- a/django-stubs/views/decorators/csrf.pyi +++ b/django-stubs/views/decorators/csrf.pyi @@ -12,7 +12,7 @@ class _EnsureCsrfToken(CsrfViewMiddleware): ... def requires_csrf_token(__view: _F) -> _F: ... class _EnsureCsrfCookie(CsrfViewMiddleware): - get_response: None + get_response: None # pyright: ignore[reportIncompatibleVariableOverride] def process_view( self, request: Any, callback: Any, callback_args: Any, callback_kwargs: Any ) -> Any: ...