Skip to content

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

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

Merged
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
3 changes: 2 additions & 1 deletion stubs/Authlib/authlib/oauth2/rfc6750/token.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from collections.abc import Callable
from typing import Protocol
from typing import Protocol, type_check_only

from authlib.oauth2.rfc6749 import ClientMixin

@type_check_only
class _TokenGenerator(Protocol):
def __call__(self, *, client: ClientMixin, grant_type: str, user, scope: str) -> str: ...

Expand Down
3 changes: 2 additions & 1 deletion stubs/Flask-Cors/flask_cors/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from collections.abc import Iterable
from datetime import timedelta
from logging import Logger
from re import Match, Pattern
from typing import Any, Final, Literal, TypedDict, TypeVar, overload
from typing import Any, Final, Literal, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias

import flask
Expand All @@ -11,6 +11,7 @@ _IterableT = TypeVar("_IterableT", bound=Iterable[Any])
_T = TypeVar("_T")
_MultiDict: TypeAlias = Any # werkzeug is not part of typeshed

@type_check_only
class _Options(TypedDict, total=False):
resources: dict[str, dict[str, Any]] | list[str] | str | None
origins: str | list[str] | None
Expand Down
3 changes: 2 additions & 1 deletion stubs/Flask-Migrate/flask_migrate/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from _typeshed import StrPath, SupportsFlush, SupportsKeysAndGetItem, SupportsWr
from argparse import Namespace
from collections.abc import Callable, Iterable, Sequence
from logging import Logger
from typing import Any, Protocol, TypeVar
from typing import Any, Protocol, TypeVar, type_check_only
from typing_extensions import ParamSpec, TypeAlias

import flask
Expand All @@ -20,6 +20,7 @@ _AlembicConfigValue: TypeAlias = Any
alembic_version: tuple[int, int, int]
log: Logger

@type_check_only
class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol): ...

class Config: # should inherit from alembic.config.Config which is not possible yet
Expand Down
7 changes: 6 additions & 1 deletion stubs/Flask-SocketIO/flask_socketio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from _typeshed import Incomplete
from collections.abc import Callable
from logging import Logger
from threading import Thread
from typing import Any, Literal, Protocol, TypedDict, TypeVar, overload
from typing import Any, Literal, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import ParamSpec, TypeAlias, Unpack

from flask import Flask
Expand All @@ -16,19 +16,23 @@ _R_co = TypeVar("_R_co", covariant=True)
_ExceptionHandler: TypeAlias = Callable[[BaseException], _R_co]
_Handler: TypeAlias = Callable[_P, _R_co]

@type_check_only
class _HandlerDecorator(Protocol):
def __call__(self, handler: _Handler[_P, _R_co]) -> _Handler[_P, _R_co]: ...

@type_check_only
class _ExceptionHandlerDecorator(Protocol):
def __call__(self, exception_handler: _ExceptionHandler[_R_co]) -> _ExceptionHandler[_R_co]: ...

@type_check_only
class _SocketIOServerOptions(TypedDict, total=False):
client_manager: Incomplete
logger: Logger | bool
json: Incomplete
async_handlers: bool
always_connect: bool

@type_check_only
class _EngineIOServerConfig(TypedDict, total=False):
async_mode: Literal["threading", "eventlet", "gevent", "gevent_uwsgi"]
ping_interval: float | tuple[float, float] # seconds
Expand All @@ -43,6 +47,7 @@ class _EngineIOServerConfig(TypedDict, total=False):
monitor_clients: bool
engineio_logger: Logger | bool

@type_check_only
class _SocketIOKwargs(_SocketIOServerOptions, _EngineIOServerConfig): ...

class SocketIO:
Expand Down
3 changes: 2 additions & 1 deletion stubs/Flask-SocketIO/flask_socketio/namespace.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from _typeshed import Incomplete
from collections.abc import Callable
from typing import Any, Protocol, TypeVar
from typing import Any, Protocol, TypeVar, type_check_only

_T = TypeVar("_T")

# at runtime, socketio.namespace.BaseNamespace, but socketio isn't py.typed
@type_check_only
class _BaseNamespace(Protocol):
def is_asyncio_based(self) -> bool: ...
def trigger_event(self, event: str, *args): ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/Flask-SocketIO/flask_socketio/test_client.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from _typeshed import Incomplete
from typing import Any, TypedDict
from typing import Any, TypedDict, type_check_only

from flask import Flask
from flask.testing import FlaskClient

@type_check_only
class _Packet(TypedDict):
name: str
args: Any
Expand Down
4 changes: 3 additions & 1 deletion stubs/JACK-Client/jack/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import Unused
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from typing import Any, Final, Literal, NoReturn, overload
from typing import Any, Final, Literal, NoReturn, overload, type_check_only
from typing_extensions import Self

import numpy
Expand All @@ -11,6 +11,7 @@ from numpy.typing import NDArray
# Actual type: _cffi_backend.__CDataOwn <cdata 'struct _jack_position *'>
# This is not a real subclassing. Just ensuring type-checkers sees this type as compatible with _CDataBase
# pyright has no error code for subclassing final
@type_check_only
class _JackPositionT(_CDataBase): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
audio_frames_per_video_frame: float
bar: int
Expand All @@ -33,6 +34,7 @@ class _JackPositionT(_CDataBase): # type: ignore[misc] # pyright: ignore[repor
valid: int
video_offset: int

@type_check_only
class _CBufferType:
@overload
def __getitem__(self, key: int) -> str: ...
Expand Down
4 changes: 3 additions & 1 deletion stubs/Markdown/markdown/extensions/toc.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Iterator, MutableSet
from re import Pattern
from typing import Any, TypedDict
from typing import Any, TypedDict, type_check_only
from typing_extensions import deprecated
from xml.etree.ElementTree import Element

Expand All @@ -10,11 +10,13 @@ from markdown.treeprocessors import Treeprocessor

IDCOUNT_RE: Pattern[str]

@type_check_only
class _FlatTocToken(TypedDict):
level: int
id: str
name: str

@type_check_only
class _TocToken(_FlatTocToken):
children: list[_TocToken]

Expand Down
3 changes: 2 additions & 1 deletion stubs/Markdown/markdown/util.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from collections.abc import Iterator
from re import Pattern
from typing import Final, Generic, TypedDict, TypeVar, overload
from typing import Final, Generic, TypedDict, TypeVar, overload, type_check_only

from markdown.core import Markdown

Expand Down Expand Up @@ -40,6 +40,7 @@ class Processor:
md: Markdown
def __init__(self, md: Markdown | None = None) -> None: ...

@type_check_only
class _TagData(TypedDict):
tag: str
attrs: dict[str, str]
Expand Down
3 changes: 2 additions & 1 deletion stubs/PyYAML/yaml/emitter.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from collections.abc import Callable
from typing import Any, NoReturn, Protocol, TypeVar
from typing import Any, NoReturn, Protocol, TypeVar, type_check_only

from yaml.error import YAMLError

from .events import Event

_T_contra = TypeVar("_T_contra", str, bytes, contravariant=True)

@type_check_only
class _WriteStream(Protocol[_T_contra]):
def write(self, data: _T_contra, /) -> object: ...
# Optional fields:
Expand Down
3 changes: 2 additions & 1 deletion stubs/Pygments/pygments/style.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from collections.abc import Iterator, Mapping, Set as AbstractSet
from typing import TypedDict
from typing import TypedDict, type_check_only

from pygments.token import _TokenType

ansicolors: AbstractSet[str] # not intended to be mutable

@type_check_only
class _StyleDict(TypedDict):
color: str | None
bold: bool
Expand Down
4 changes: 3 additions & 1 deletion stubs/WTForms/wtforms/fields/core.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...

Expand Down
3 changes: 2 additions & 1 deletion stubs/WTForms/wtforms/form.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/WTForms/wtforms/i18n.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
6 changes: 5 additions & 1 deletion stubs/WTForms/wtforms/meta.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,13 +9,15 @@ 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: ...

# 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: ...
Expand All @@ -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]: ...

Expand Down
3 changes: 2 additions & 1 deletion stubs/WebOb/webob/acceptparse.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import SupportsItems
from collections.abc import Callable, Iterable, Iterator, Sequence
from typing import Any, Literal, NamedTuple, Protocol, TypeVar, overload
from typing import Any, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias

from webob._types import AsymmetricPropertyWithDelete
Expand All @@ -9,6 +9,7 @@ _T = TypeVar("_T")
_ListOrTuple: TypeAlias = list[_T] | tuple[_T, ...]
_ParsedAccept: TypeAlias = tuple[str, float, list[tuple[str, str]], list[str | tuple[str, str]]]

@type_check_only
class _SupportsStr(Protocol):
def __str__(self) -> str: ... # noqa: Y029

Expand Down
3 changes: 2 additions & 1 deletion stubs/WebOb/webob/cookies.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from _typeshed.wsgi import WSGIEnvironment
from collections.abc import Collection, ItemsView, Iterator, KeysView, MutableMapping, ValuesView
from datetime import date, datetime, timedelta
from time import _TimeTuple, struct_time
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 webob._types import AsymmetricProperty
Expand All @@ -26,6 +26,7 @@ _T = TypeVar("_T")
# valid spellings, but it seems more natural to support these two spellings
_SameSitePolicy: TypeAlias = Literal["Strict", "Lax", "None", "strict", "lax", "none"]

@type_check_only
class _Serializer(Protocol):
def dumps(self, appstruct: Any, /) -> bytes: ...
def loads(self, bstruct: bytes, /) -> Any: ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/WebOb/webob/dec.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment
from collections.abc import Callable, Iterable, Mapping
from typing import Any, Generic, overload
from typing import Any, Generic, overload, type_check_only
from typing_extensions import Concatenate, Never, ParamSpec, Self, TypeAlias, TypeVar

from webob.request import BaseRequest, Request
Expand Down Expand Up @@ -145,6 +145,7 @@ class wsgify(Generic[_P, _RequestT_contra]):
cls, middle_func: _MiddlewareMethod[_RequestT, _AppT, _P2], app: _AppT, *_: _P2.args, **kw: _P2.kwargs
) -> type[wsgify[Concatenate[_AppT, _P2], _RequestT]]: ...

@type_check_only
class _unbound_wsgify(wsgify[_P, _RequestT_contra], Generic[_P, _S, _RequestT_contra]):
@overload # type: ignore[override]
def __call__(self, __self: _S, env: WSGIEnvironment, /, start_response: StartResponse) -> Iterable[bytes]: ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/WebOb/webob/exc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from _typeshed import SupportsItems, SupportsKeysAndGetItem
from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment
from collections.abc import Iterable
from string import Template
from typing import Any, Literal, Protocol
from typing import Any, Literal, Protocol, type_check_only
from typing_extensions import Self, TypeAlias

from webob.response import Response
Expand Down Expand Up @@ -68,6 +68,7 @@ __all__ = [

_Headers: TypeAlias = SupportsItems[str, str] | SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]]

@type_check_only
class _JSONFormatter(Protocol):
def __call__(self, *, body: str, status: str, title: str, environ: WSGIEnvironment) -> Any: ...

Expand Down
3 changes: 2 additions & 1 deletion stubs/WebOb/webob/multidict.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _typeshed import SupportsKeysAndGetItem
from _typeshed.wsgi import WSGIEnvironment
from collections.abc import Collection, Iterable, Iterator, MutableMapping
from typing import Literal, Protocol, TypeVar, overload
from typing import Literal, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Self

from webob.compat import cgi_FieldStorage, cgi_FieldStorage as _FieldStorageWithFile
Expand All @@ -14,6 +14,7 @@ _VT = TypeVar("_VT")
_KT_co = TypeVar("_KT_co", covariant=True)
_VT_co = TypeVar("_VT_co", covariant=True)

@type_check_only
class _SupportsItemsWithIterableResult(Protocol[_KT_co, _VT_co]):
def items(self) -> Iterable[tuple[_KT_co, _VT_co]]: ...

Expand Down
4 changes: 3 additions & 1 deletion stubs/WebOb/webob/request.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from _typeshed import OptExcInfo, SupportsKeysAndGetItem, SupportsNoArgReadline,
from _typeshed.wsgi import WSGIApplication, WSGIEnvironment
from collections.abc import Iterable, Mapping
from re import Pattern
from typing import IO, Any, ClassVar, Literal, Protocol, TypedDict, TypeVar, overload
from typing import IO, Any, ClassVar, Literal, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias

from webob._types import AsymmetricProperty, AsymmetricPropertyWithDelete, SymmetricProperty, SymmetricPropertyWithDelete
Expand All @@ -27,8 +27,10 @@ _HTTPMethod: TypeAlias = Literal["GET", "HEAD", "POST", "PUT", "DELETE", "CONNEC
_ListOrTuple: TypeAlias = list[_T] | tuple[_T, ...]
_RequestCacheControl: TypeAlias = CacheControl[Literal["request"]]

@type_check_only
class _SupportsReadAndNoArgReadline(SupportsRead[str | bytes], SupportsNoArgReadline[str | bytes], Protocol): ...

@type_check_only
class _RequestCacheControlDict(TypedDict, total=False):
max_stale: int
min_stale: int
Expand Down
Loading
Loading