Skip to content

Commit

Permalink
Update utils (#2352)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos authored Aug 24, 2024
1 parent 2dfa15b commit 9a0f113
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 40 deletions.
3 changes: 1 addition & 2 deletions django-stubs/utils/deprecation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ from django.http.request import HttpRequest
from django.http.response import HttpResponseBase
from typing_extensions import TypeAlias

class RemovedInDjango51Warning(DeprecationWarning): ...
class RemovedInNextVersionWarning(DeprecationWarning): ...
class RemovedInDjango60Warning(PendingDeprecationWarning): ...

RemovedInNextVersionWarning: TypeAlias = RemovedInDjango51Warning
RemovedAfterNextVersionWarning: TypeAlias = RemovedInDjango60Warning

class warn_about_renamed_method:
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/utils/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from _typeshed import Incomplete
from django.utils.functional import SimpleLazyObject, _StrOrPromise
from django.utils.safestring import SafeData, SafeString

VOID_ELEMENTS: set[str]
VOID_ELEMENTS: frozenset[str]
MAX_URL_LENGTH: int

def escape(text: Any) -> SafeString: ...
Expand Down
3 changes: 3 additions & 0 deletions django-stubs/utils/inspect.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from collections.abc import Callable
from inspect import _ParameterKind
from typing import Any

ARG_KINDS: frozenset[_ParameterKind]

def get_func_args(func: Callable[..., Any]) -> list[str]: ...
def get_func_full_args(func: Callable[..., Any]) -> list[tuple[str, str] | tuple[str]]: ...
def func_accepts_kwargs(func: Callable[..., Any]) -> bool: ...
Expand Down
33 changes: 16 additions & 17 deletions django-stubs/utils/text.pyi
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
from collections.abc import Callable, Iterable, Iterator
from html.parser import HTMLParser
from io import BytesIO
from re import Match, Pattern
from re import Pattern
from typing import ClassVar, TypeVar, overload

from django.db.models.base import Model
from django.utils.functional import SimpleLazyObject, _StrOrPromise
from django.utils.functional import SimpleLazyObject, _StrOrPromise, cached_property

_StrOrPromiseT = TypeVar("_StrOrPromiseT", bound=_StrOrPromise)
_StrOrPromiseOrNoneT = TypeVar("_StrOrPromiseOrNoneT", bound=_StrOrPromise | None)

def capfirst(x: _StrOrPromiseOrNoneT) -> _StrOrPromiseOrNoneT: ...

re_notag: Pattern[str]
re_prt: Pattern[str]

class WordsRegex:
@staticmethod
def search(text: str, pos: int) -> Match | FakeMatch: ...

class FakeMatch:
def __init__(self, text: str, end: int) -> None: ...
def __getitem__(self, group: int) -> str | None: ...
def end(self, group: int = 0) -> int: ...

re_words: type[WordsRegex]
re_chars: Pattern[str]
re_tag: Pattern[str]
re_newlines: Pattern[str]
re_camel_case: Pattern[str]

def wrap(text: _StrOrPromiseT, width: int) -> _StrOrPromiseT: ...
def add_truncation_text(text: str, truncate: str | None = None) -> str: ...
def calculate_truncate_chars_length(length: int, replacement: str | None) -> int: ...

class TruncateHTMLParser(HTMLParser):
TruncationCompleted: ClassVar[type[Exception]]
def __init__(self, *, length: int, replacement: str | None, convert_charrefs: bool = True) -> None: ...
@cached_property
def void_elements(self) -> frozenset[str]: ...

class TruncateCharsHTMLParser(TruncateHTMLParser):
def process(self, data: str) -> tuple[str, str]: ...

class TruncateWordsHTMLParser(TruncateHTMLParser):
def process(self, data: str) -> tuple[str, str]: ...

class Truncator(SimpleLazyObject):
MAX_LENGTH_HTML: ClassVar[int]
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/utils/version.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing_extensions import TypeAlias

PY36: bool
PY37: bool
PYPY: bool

PY38: bool
PY39: bool
PY310: bool
PY311: bool
PY312: bool
PY313: bool

_VT: TypeAlias = tuple[int, int, int, str, int]

Expand Down
5 changes: 1 addition & 4 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ django.utils.http.ASCTIME_DATE
django.utils.http.ETAG_MATCH
django.utils.http.RFC1123_DATE
django.utils.http.RFC850_DATE
django.utils.text.re_notag
django.utils.text.re_prt
django.utils.text.re_chars
django.utils.text.re_tag
django.utils.text.re_newlines
django.utils.text.re_camel_case
django.utils.text.smart_split_re
Expand Down Expand Up @@ -404,6 +400,7 @@ django.utils.connection.BaseConnectionHandler.settings
django.utils.html.Urlizer.trailing_punctuation_chars_has_semicolon
django.utils.html.Urlizer.trailing_punctuation_chars_no_semicolon
django.utils.html.Urlizer.wrapping_punctuation_openings
django.utils.text.TruncateHTMLParser.void_elements
django.db.models.Q.referenced_base_fields
django.db.models.query_utils.Q.referenced_base_fields
django.contrib.gis.db.models.Q.referenced_base_fields
Expand Down
14 changes: 0 additions & 14 deletions scripts/stubtest/allowlist_todo_django51.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,6 @@ django.test.utils.garbage_collect
django.urls.converters.get_converter
django.urls.resolvers.LocaleRegexRouteDescriptor
django.urls.resolvers.whitespace_set
django.utils.deprecation.RemovedInDjango51Warning
django.utils.html.VOID_ELEMENTS
django.utils.inspect.ARG_KINDS
django.utils.text.FakeMatch
django.utils.text.TruncateCharsHTMLParser
django.utils.text.TruncateHTMLParser
django.utils.text.TruncateWordsHTMLParser
django.utils.text.WordsRegex
django.utils.text.calculate_truncate_chars_length
django.utils.text.re_words
django.utils.version.PY313
django.utils.version.PY36
django.utils.version.PY37
django.utils.version.PYPY

# Only discrepancies that appeared after Django 4.2 -> 5.0 update.
# Unsorted: there are real problems and things we can really ignore:
Expand Down

0 comments on commit 9a0f113

Please sign in to comment.