Mark stub-only private symbols as @type_check_only in third-party stubs (#14545)

This commit is contained in:
Brian Schubert
2025-08-08 11:29:48 +02:00
committed by GitHub
parent a358dc24e8
commit 81c8fcb2e6
131 changed files with 334 additions and 147 deletions
+3 -1
View File
@@ -1,6 +1,6 @@
from builtins import type as _type # type is being shadowed in Field
from collections.abc import Callable, Iterable, Sequence
from typing import Any, Generic, Protocol, TypeVar, overload
from typing import Any, Generic, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias
from markupsafe import Markup
@@ -16,9 +16,11 @@ _FieldT_contra = TypeVar("_FieldT_contra", bound=Field, contravariant=True)
# trust, that people won't use it to change the type of data in a field...
_Filter: TypeAlias = Callable[[Any], Any]
@type_check_only
class _Validator(Protocol[_FormT_contra, _FieldT_contra]):
def __call__(self, form: _FormT_contra, field: _FieldT_contra, /) -> object: ...
@type_check_only
class _Widget(Protocol[_FieldT_contra]):
def __call__(self, field: _FieldT_contra, **kwargs: Any) -> Markup: ...
+2 -1
View File
@@ -1,6 +1,6 @@
from _typeshed import SupportsItems
from collections.abc import Iterable, Iterator, Mapping, Sequence
from typing import Any, ClassVar, Protocol, TypeVar, overload
from typing import Any, ClassVar, Protocol, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias
from wtforms.fields.core import Field, UnboundField
@@ -12,6 +12,7 @@ _FormErrors: TypeAlias = dict[str, Sequence[str] | _FormErrors]
# _unbound_fields will always be a list on an instance, but on a
# class it might be None, if it never has been instantiated, or
# not instantianted after a new field had been added/removed
@type_check_only
class _UnboundFields(Protocol):
@overload
def __get__(self, obj: None, owner: type[object] | None = None, /) -> list[tuple[str, UnboundField[Any]]] | None: ...
+2 -1
View File
@@ -1,9 +1,10 @@
from collections.abc import Callable, Iterable
from gettext import GNUTranslations
from typing import Protocol, TypeVar, overload
from typing import Protocol, TypeVar, overload, type_check_only
_T = TypeVar("_T")
@type_check_only
class _SupportsUgettextAndUngettext(Protocol):
def ugettext(self, string: str, /) -> str: ...
def ungettext(self, singular: str, plural: str, n: int, /) -> str: ...
+5 -1
View File
@@ -1,6 +1,6 @@
from _typeshed import SupportsItems
from collections.abc import Collection, Iterator, MutableMapping
from typing import Any, Literal, Protocol, TypeVar, overload
from typing import Any, Literal, Protocol, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias
from markupsafe import Markup
@@ -9,6 +9,7 @@ from wtforms.form import BaseForm
_FieldT = TypeVar("_FieldT", bound=Field)
@type_check_only
class _SupportsGettextAndNgettext(Protocol):
def gettext(self, string: str, /) -> str: ...
def ngettext(self, singular: str, plural: str, n: int, /) -> str: ...
@@ -16,6 +17,7 @@ class _SupportsGettextAndNgettext(Protocol):
# these are the methods WTForms depends on, the dict can either provide
# a getlist or getall, if it only provides getall, it will wrapped, to
# provide getlist instead
@type_check_only
class _MultiDictLikeBase(Protocol):
def __iter__(self) -> Iterator[str]: ...
def __len__(self) -> int: ...
@@ -24,9 +26,11 @@ class _MultiDictLikeBase(Protocol):
# since how file uploads are represented in formdata is implementation-specific
# we have to be generous in what we accept in the return of getlist/getall
# we can make this generic if we ever want to be more specific
@type_check_only
class _MultiDictLikeWithGetlist(_MultiDictLikeBase, Protocol):
def getlist(self, key: str, /) -> list[Any]: ...
@type_check_only
class _MultiDictLikeWithGetall(_MultiDictLikeBase, Protocol):
def getall(self, key: str, /) -> list[Any]: ...