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

Misc test stubs types #1752

Merged
merged 6 commits into from
Oct 3, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django-stubs/core/management/commands/makemessages.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Any

from django.core.management.base import BaseCommand

plural_forms_re: Pattern
plural_forms_re: Pattern[str]
STATUS_OK: int
NO_LOCALE_DIR: Any

Expand Down
3 changes: 2 additions & 1 deletion django-stubs/test/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .client import AsyncClient as AsyncClient
from .client import AsyncRequestFactory as AsyncRequestFactory
from .client import Client as Client
from .client import RequestFactory as RequestFactory
from .testcases import LiveServerTestCase as LiveServerTestCase
Expand All @@ -9,7 +11,6 @@ from .testcases import skipUnlessAnyDBFeature as skipUnlessAnyDBFeature
from .testcases import skipUnlessDBFeature as skipUnlessDBFeature
from .utils import ignore_warnings as ignore_warnings
from .utils import modify_settings as modify_settings
from .utils import override_script_prefix as override_script_prefix
from .utils import override_settings as override_settings
from .utils import override_system_checks as override_system_checks
from .utils import tag as tag
28 changes: 20 additions & 8 deletions django-stubs/test/client.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Awaitable, Callable, Iterable, Iterator, Mapping
from io import BytesIO
from io import BytesIO, IOBase
from json import JSONEncoder
from re import Pattern
from types import TracebackType
Expand All @@ -20,19 +20,20 @@ from typing_extensions import TypeAlias

BOUNDARY: str
MULTIPART_CONTENT: str
CONTENT_TYPE_RE: Pattern
JSON_CONTENT_TYPE_RE: Pattern
CONTENT_TYPE_RE: Pattern[str]
JSON_CONTENT_TYPE_RE: Pattern[str]

class RedirectCycleError(Exception):
last_response: HttpResponseBase
redirect_chain: list[tuple[str, int]]
def __init__(self, message: str, last_response: HttpResponseBase) -> None: ...

class FakePayload:
class FakePayload(IOBase):
read_started: bool
def __init__(self, content: bytes | str | None = ...) -> None: ...
def __init__(self, initial_bytes: bytes | str | None = ...) -> None: ...
def __len__(self) -> int: ...
def read(self, num_bytes: int = ...) -> bytes: ...
def read(self, size: int = ...) -> bytes: ...
def readline(self, size: int | None = ..., /) -> bytes: ...
def write(self, content: bytes | str) -> None: ...

_T = TypeVar("_T")
Expand Down Expand Up @@ -229,10 +230,11 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
headers: Mapping[str, Any] | None = ...,
**extra: Any,
) -> _MonkeyPatchedWSGIResponse: ...
def trace( # type: ignore[override]
def options( # type: ignore[override]
self,
path: str,
data: Any = ...,
data: dict[str, str] | str = ...,
content_type: str = ...,
follow: bool = ...,
secure: bool = ...,
*,
Expand Down Expand Up @@ -272,6 +274,16 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
headers: Mapping[str, Any] | None = ...,
**extra: Any,
) -> _MonkeyPatchedWSGIResponse: ...
def trace( # type: ignore[override]
self,
path: str,
data: Any = ...,
follow: bool = ...,
secure: bool = ...,
*,
headers: Mapping[str, Any] | None = ...,
**extra: Any,
) -> _MonkeyPatchedWSGIResponse: ...

class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGIResponse]]):
handler: AsyncClientHandler
Expand Down
6 changes: 5 additions & 1 deletion django-stubs/test/html.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from collections.abc import Sequence
from html.parser import HTMLParser
from re import Pattern
from typing import Any

from typing_extensions import TypeAlias

WHITESPACE: Any
ASCII_WHITESPACE: Pattern[str]
BOOLEAN_ATTRIBUTES: set[str]

def normalize_whitespace(string: str) -> str: ...
def normalize_attributes(attributes: list[tuple[str, str | None]]) -> list[tuple[str, str | None]]: ...

_ElementAttribute: TypeAlias = tuple[str, str | None]

Expand All @@ -32,6 +35,7 @@ class Parser(HTMLParser):
open_tags: Any
element_positions: Any
def __init__(self) -> None: ...
def error(self, msg: str) -> HTMLParseError: ...
def format_position(self, position: Any = ..., element: Any = ...) -> str: ...
@property
def current(self) -> Element: ...
Expand Down
1 change: 1 addition & 0 deletions django-stubs/test/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TestContextDecorator:
def __call__(self, decorated: _DT) -> _DT: ...

class override_settings(TestContextDecorator):
enable_exception: Exception | None
options: dict[str, Any]
def __init__(self, **kwargs: Any) -> None: ...
wrapped: Settings
Expand Down
18 changes: 18 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ django.utils.functional.Promise.__radd__
django.utils.functional.Promise.__mod__

# Lazy regex
django.contrib.admin.utils.UNQUOTE_RE
django.contrib.gis.geometry.hex_regex
django.contrib.gis.geometry.json_regex
django.contrib.gis.geometry.wkt_regex
django.contrib.gis.geos.hex_regex
django.contrib.gis.geos.wkt_regex
django.core.validators.EmailValidator.domain_regex
django.core.validators.EmailValidator.literal_regex
django.core.validators.EmailValidator.user_regex
django.core.validators.slug_re
django.core.validators.slug_unicode_re
django.core.management.commands.makemessages.plural_forms_re
django.http.request.host_validation_re
django.template.base.filter_re
django.template.base.kwarg_re
django.test.client.CONTENT_TYPE_RE
django.test.client.JSON_CONTENT_TYPE_RE
django.test.html.ASCII_WHITESPACE
django.utils.dateformat.re_escaped
django.utils.dateformat.re_formatchars
django.utils.dateparse.date_re
Expand Down
33 changes: 0 additions & 33 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ django.contrib.admin.utils.NestedObjects.collect
django.contrib.admin.utils.NestedObjects.nested
django.contrib.admin.utils.QUOTE_MAP
django.contrib.admin.utils.UNQUOTE_MAP
django.contrib.admin.utils.UNQUOTE_RE
django.contrib.admin.utils.prepare_lookup_value
django.contrib.admin.views.autocomplete.AutocompleteJsonView.admin_site
django.contrib.admin.views.autocomplete.AutocompleteJsonView.process_request
Expand Down Expand Up @@ -641,24 +640,19 @@ django.contrib.gis.gdal.srs.SpatialReference.xml
django.contrib.gis.geoip2.GeoIP2
django.contrib.gis.geoip2.GeoIP2Exception
django.contrib.gis.geoip2.base
django.contrib.gis.geometry.hex_regex
django.contrib.gis.geometry.json_regex
django.contrib.gis.geometry.wkt_regex
django.contrib.gis.geos.GEOSGeometry.__new__
django.contrib.gis.geos.Point.tuple
django.contrib.gis.geos.geometry.GEOSGeometry.__new__
django.contrib.gis.geos.geometry.GEOSGeometryBase.geojson
django.contrib.gis.geos.geometry.GEOSGeometryBase.make_valid
django.contrib.gis.geos.geometry.GEOSGeometryBase.normalize
django.contrib.gis.geos.hex_regex
django.contrib.gis.geos.libgeos.error_h
django.contrib.gis.geos.libgeos.notice_h
django.contrib.gis.geos.mutable_list.ListMixin.__ge__
django.contrib.gis.geos.mutable_list.ListMixin.__gt__
django.contrib.gis.geos.mutable_list.ListMixin.__le__
django.contrib.gis.geos.point.Point.tuple
django.contrib.gis.geos.prototypes.geom.geos_makevalid
django.contrib.gis.geos.wkt_regex
django.contrib.gis.measure.MeasureBase.__ge__
django.contrib.gis.measure.MeasureBase.__gt__
django.contrib.gis.measure.MeasureBase.__le__
Expand Down Expand Up @@ -970,7 +964,6 @@ django.core.management.commands.makemessages.TranslatableFile.__le__
django.core.management.commands.makemessages.TranslatableFile.__lt__
django.core.management.commands.makemessages.TranslatableFile.path
django.core.management.commands.makemessages.is_valid_locale
django.core.management.commands.makemessages.plural_forms_re
django.core.management.commands.runserver.Command.on_bind
django.core.management.commands.runserver.Command.suppressed_base_arguments
django.core.management.commands.runserver.naiveip_re
Expand Down Expand Up @@ -1005,9 +998,6 @@ django.core.signing.loads
django.core.validators.BaseValidator.__new__
django.core.validators.DecimalValidator.__new__
django.core.validators.EmailValidator.__new__
django.core.validators.EmailValidator.domain_regex
django.core.validators.EmailValidator.literal_regex
django.core.validators.EmailValidator.user_regex
django.core.validators.FileExtensionValidator.__new__
django.core.validators.MaxLengthValidator.__new__
django.core.validators.MaxValueValidator.__new__
Expand All @@ -1020,8 +1010,6 @@ django.core.validators.URLValidator.__new__
django.core.validators.URLValidator.regex
django.core.validators.URLValidator.unsafe_chars
django.core.validators.URLValidator.max_length
django.core.validators.slug_re
django.core.validators.slug_unicode_re
django.db.backends.base.base.BaseDatabaseWrapper.SchemaEditorClass
django.db.backends.base.base.BaseDatabaseWrapper.client_class
django.db.backends.base.base.BaseDatabaseWrapper.close_if_health_check_failed
Expand Down Expand Up @@ -2162,7 +2150,6 @@ django.http.request.HttpRequest.headers
django.http.request.HttpRequest.is_ajax
django.http.request.HttpRequest.readlines
django.http.request.UploadHandlerList
django.http.request.host_validation_re
django.http.request.parse_accept_header
django.http.response.HttpResponseBase.__iter__
django.http.response.HttpResponseBase.getvalue
Expand Down Expand Up @@ -2199,8 +2186,6 @@ django.template.base.Context
django.template.base.FilterExpression.is_var
django.template.base.Node.__iter__
django.template.base.VariableDoesNotExist.__init__
django.template.base.filter_re
django.template.base.kwarg_re
django.template.defaultfilters.json_script
django.template.defaulttags.IfEqualNode
django.template.defaulttags.do_ifequal
Expand All @@ -2226,28 +2211,11 @@ django.templatetags.static.PrefixNode.__init__
django.templatetags.static.StaticNode.__init__
django.templatetags.tz.UnknownTimezoneException
django.templatetags.tz.timezone_constructor
django.test.AsyncClient
django.test.AsyncRequestFactory
django.test.Client.options
django.test.SimpleTestCase.assertFormError
django.test.SimpleTestCase.assertFormSetError
django.test.SimpleTestCase.assertTemplateNotUsed
django.test.TransactionTestCase.assertNumQueries
django.test.TransactionTestCase.assertQuerySetEqual
django.test.client.CONTENT_TYPE_RE
django.test.client.Client.options
django.test.client.FakePayload
django.test.client.FakePayload.__init__
django.test.client.FakePayload.read
django.test.client.FakePayload.readline
django.test.client.JSON_CONTENT_TYPE_RE
django.test.html.ASCII_WHITESPACE
django.test.html.BOOLEAN_ATTRIBUTES
django.test.html.Parser.error
django.test.html.WHITESPACE
django.test.html.normalize_attributes
django.test.override_script_prefix
django.test.override_settings.enable_exception
django.test.runner.DiscoverRunner.build_suite
django.test.runner.DiscoverRunner.log
django.test.runner.DiscoverRunner.reorder_by
Expand Down Expand Up @@ -2311,7 +2279,6 @@ django.test.testcases.TransactionTestCase.assertQuerySetEqual
django.test.testcases._AssertTemplateUsedContext.__init__
django.test.testcases._AssertTemplateUsedContext.message
django.test.utils.TimeKeeperProtocol
django.test.utils.override_settings.enable_exception
django.test.utils.setup_databases
django.urls.ResolverMatch.__iter__
django.urls.conf.path
Expand Down