From b6482f1e2c33cf7952bbb747a9e4d3faff28f817 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Mon, 11 Sep 2023 20:59:01 +0200 Subject: [PATCH] Properly type SimpleCookie. This definition makes it usable even in pyright's strict mode. See https://github.com/microsoft/pyright/issues/5927 for details. --- django-stubs/http/cookie.pyi | 4 +--- django-stubs/http/response.pyi | 2 +- django-stubs/template/response.pyi | 4 ++-- django-stubs/test/client.pyi | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/django-stubs/http/cookie.pyi b/django-stubs/http/cookie.pyi index 4e5654e6c..efa3fb93a 100644 --- a/django-stubs/http/cookie.pyi +++ b/django-stubs/http/cookie.pyi @@ -1,5 +1,3 @@ -from typing import Any - -SimpleCookie: Any +from http.cookies import SimpleCookie as SimpleCookie def parse_cookie(cookie: str) -> dict[str, str]: ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi index bc63ee9bd..c1cbeb962 100644 --- a/django-stubs/http/response.pyi +++ b/django-stubs/http/response.pyi @@ -1,10 +1,10 @@ import datetime from collections.abc import AsyncIterable, AsyncIterator, Iterable, Iterator +from http.cookies import SimpleCookie from io import BytesIO from json import JSONEncoder from typing import Any, Literal, TypeVar, overload, type_check_only -from django.http.cookie import SimpleCookie from django.utils.datastructures import CaseInsensitiveMapping, _PropertyDescriptor class BadHeaderError(ValueError): ... diff --git a/django-stubs/template/response.pyi b/django-stubs/template/response.pyi index b3c4bf611..da40f8ca3 100644 --- a/django-stubs/template/response.pyi +++ b/django-stubs/template/response.pyi @@ -20,7 +20,7 @@ class ContentNotRenderedError(Exception): ... class SimpleTemplateResponse(HttpResponse): content: Any closed: bool - cookies: SimpleCookie[str] + cookies: SimpleCookie status_code: int rendering_attrs: Any template_name: _TemplateForResponseT @@ -51,7 +51,7 @@ class TemplateResponse(SimpleTemplateResponse): closed: bool context: RequestContext context_data: dict[str, Any] | None - cookies: SimpleCookie[str] + cookies: SimpleCookie csrf_cookie_set: bool json: functools.partial _request: HttpRequest diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index 43a4a1e97..1eaf19d8c 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -1,4 +1,5 @@ from collections.abc import Awaitable, Callable, Iterable, Iterator, Mapping +from http.cookies import SimpleCookie from io import BytesIO from json import JSONEncoder from re import Pattern @@ -10,7 +11,6 @@ from django.contrib.sessions.backends.base import SessionBase from django.core.handlers.asgi import ASGIRequest from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import WSGIRequest -from django.http.cookie import SimpleCookie from django.http.request import HttpRequest from django.http.response import HttpResponseBase from django.template.base import Template