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

Use PEP 570 syntax in third party stubs #11554

Merged
merged 3 commits into from
Mar 10, 2024
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 stubs/Deprecated/deprecated/classic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClassicAdapter:
def __call__(self, wrapped: _F) -> Callable[[_F], _F]: ...

@overload
def deprecated(__wrapped: _F) -> _F: ...
def deprecated(wrapped: _F, /) -> _F: ...
@overload
def deprecated(
reason: str = ..., *, version: str = ..., action: _Actions | None = ..., category: type[Warning] | None = ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/ExifRead/exifread/_types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ TagDict: TypeAlias = dict[int, tuple[str] | tuple[str, Any]]

class Reader(Protocol):
def __iter__(self) -> bytes: ...
def read(self, __size: int) -> bytes: ...
def read(self, size: int, /) -> bytes: ...
def tell(self) -> int: ...
def seek(self, __offset: int, __whence: Literal[0, 1] = ...) -> object: ...
def seek(self, offset: int, whence: Literal[0, 1] = ..., /) -> object: ...
2 changes: 1 addition & 1 deletion stubs/Flask-SocketIO/flask_socketio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SocketIO:
def on_error_default(self, exception_handler: _ExceptionHandler[_R_co]) -> _ExceptionHandler[_R_co]: ...
def on_event(self, message: str, handler: _Handler[[Incomplete], object], namespace: str | None = None) -> None: ...
@overload
def event(self, __event_handler: _Handler[_P, _R_co]) -> _Handler[_P, _R_co]: ...
def event(self, event_handler: _Handler[_P, _R_co], /) -> _Handler[_P, _R_co]: ...
@overload
def event(self, namespace: str | None = None, *args, **kwargs) -> _HandlerDecorator: ...
def on_namespace(self, namespace_handler: Namespace) -> None: ...
Expand Down
8 changes: 4 additions & 4 deletions stubs/Markdown/markdown/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ from .util import HtmlStash, Registry
# TODO: The following protocols can be replaced by their counterparts from
# codecs, once they have been propagated to all type checkers.
class _WritableStream(Protocol):
def write(self, __data: bytes) -> object: ...
def seek(self, __offset: int, __whence: int) -> object: ...
def write(self, data: bytes, /) -> object: ...
def seek(self, offset: int, whence: int, /) -> object: ...
def close(self) -> object: ...

class _ReadableStream(Protocol):
def read(self, __size: int = ...) -> bytes: ...
def seek(self, __offset: int, __whence: int) -> object: ...
def read(self, size: int = ..., /) -> bytes: ...
def seek(self, offset: int, whence: int, /) -> object: ...
def close(self) -> object: ...

class Markdown:
Expand Down
2 changes: 1 addition & 1 deletion stubs/Pillow/PIL/Image.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _Color: TypeAlias = (
)

class _Writeable(SupportsWrite[bytes], Protocol):
def seek(self, __offset: int) -> Any: ...
def seek(self, offset: int, /) -> Any: ...

# Ref: https://numpy.org/doc/stable/reference/arrays.interface.html#python-side
class _SupportsArrayInterface(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion stubs/Pillow/PIL/ImageFont.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Layout(IntEnum):
MAX_STRING_LENGTH: Final[int] = 1_000_000

class _Font(Protocol):
def getmask(self, __text: str | bytes, __mode: str = ..., direction=..., features=...): ...
def getmask(self, text: str | bytes, mode: str = ..., /, direction=..., features=...): ...

class ImageFont:
def getmask(self, text: str | bytes, mode: str = "", direction=..., features=...): ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/Pillow/PIL/ImageOps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from .ImageColor import _Ink
_Border: TypeAlias = int | tuple[int, int] | tuple[int, int, int, int]

class _Deformer(Protocol):
def getmesh(self, __image: Image): ...
def getmesh(self, image: Image, /): ...

def autocontrast(
image: Image,
Expand Down
12 changes: 6 additions & 6 deletions stubs/Pillow/PIL/_imaging.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class _PixelAccessor(Protocol): # noqa: Y046
#
# This protocol describes that interface.
# TODO: should the color args and getter return types be _Color?
def __setitem__(self, __xy: tuple[int, int], __color: Incomplete) -> None: ...
def __getitem__(self, __xy: tuple[int, int]) -> Incomplete: ...
def putpixel(self, __xy: tuple[int, int], __color: Incomplete) -> None: ...
def getpixel(self, __xy: tuple[int, int]) -> Incomplete: ...
def __setitem__(self, xy: tuple[int, int], color: Incomplete, /) -> None: ...
def __getitem__(self, xy: tuple[int, int], /) -> Incomplete: ...
def putpixel(self, xy: tuple[int, int], color: Incomplete, /) -> None: ...
def getpixel(self, xy: tuple[int, int], /) -> Incomplete: ...

class _Path:
def __getattr__(self, item: str) -> Incomplete: ...

def path(__x: Sequence[tuple[float, float]] | Sequence[float]) -> _Path: ...
def __getattr__(__name: str) -> Incomplete: ...
def path(x: Sequence[tuple[float, float]] | Sequence[float], /) -> _Path: ...
def __getattr__(name: str, /) -> Incomplete: ...
2 changes: 1 addition & 1 deletion stubs/PyYAML/yaml/emitter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from .events import Event
_T_contra = TypeVar("_T_contra", str, bytes, contravariant=True)

class _WriteStream(Protocol[_T_contra]):
def write(self, __data: _T_contra) -> object: ...
def write(self, data: _T_contra, /) -> object: ...
# Optional fields:
# encoding: str
# def flush(self) -> object: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/WTForms/wtforms/fields/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _FieldT_contra = TypeVar("_FieldT_contra", bound=Field, contravariant=True)
_Filter: TypeAlias = Callable[[Any], Any]

class _Validator(Protocol[_FormT_contra, _FieldT_contra]):
def __call__(self, __form: _FormT_contra, __field: _FieldT_contra) -> object: ...
def __call__(self, form: _FormT_contra, field: _FieldT_contra, /) -> object: ...

class _Widget(Protocol[_FieldT_contra]):
def __call__(self, field: _FieldT_contra, **kwargs: Any) -> Markup: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/WTForms/wtforms/form.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ _FormErrors: TypeAlias = dict[str | None, Sequence[str] | _FormErrors]
# not instantianted after a new field had been added/removed
class _UnboundFields(Protocol):
@overload
def __get__(self, __obj: None, __owner: type[object] | None = None) -> list[tuple[str, UnboundField[Any]]] | None: ...
def __get__(self, obj: None, owner: type[object] | None = None, /) -> list[tuple[str, UnboundField[Any]]] | None: ...
@overload
def __get__(self, __obj: object, __owner: type[object] | None = None) -> list[tuple[str, UnboundField[Any]]]: ...
def __get__(self, obj: object, owner: type[object] | None = None, /) -> list[tuple[str, UnboundField[Any]]]: ...

class BaseForm:
meta: DefaultMeta
Expand Down
4 changes: 2 additions & 2 deletions stubs/WTForms/wtforms/i18n.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ from typing import Protocol, TypeVar, overload
_T = TypeVar("_T")

class _SupportsUgettextAndUngettext(Protocol):
def ugettext(self, __string: str) -> str: ...
def ungettext(self, __singular: str, __plural: str, __n: int) -> str: ...
def ugettext(self, string: str, /) -> str: ...
def ungettext(self, singular: str, plural: str, n: int, /) -> str: ...

def messages_path() -> str: ...
def get_builtin_gnu_translations(languages: Iterable[str] | None = None) -> GNUTranslations: ...
Expand Down
10 changes: 5 additions & 5 deletions stubs/WTForms/wtforms/meta.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ from wtforms.form import BaseForm
_FieldT = TypeVar("_FieldT", bound=Field)

class _SupportsGettextAndNgettext(Protocol):
def gettext(self, __string: str) -> str: ...
def ngettext(self, __singular: str, __plural: str, __n: int) -> str: ...
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
class _MultiDictLikeBase(Protocol):
def __iter__(self) -> Iterator[str]: ...
def __len__(self) -> int: ...
def __contains__(self, __key: Any) -> bool: ...
def __contains__(self, key: Any, /) -> bool: ...

# 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
class _MultiDictLikeWithGetlist(_MultiDictLikeBase, Protocol):
def getlist(self, __key: str) -> list[Any]: ...
def getlist(self, key: str, /) -> list[Any]: ...

class _MultiDictLikeWithGetall(_MultiDictLikeBase, Protocol):
def getall(self, __key: str) -> list[Any]: ...
def getall(self, key: str, /) -> list[Any]: ...

_MultiDictLike: TypeAlias = _MultiDictLikeWithGetall | _MultiDictLikeWithGetlist

Expand Down
56 changes: 28 additions & 28 deletions stubs/WebOb/webob/acceptparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ def create_accept_header(header_value: str) -> AcceptValidHeader | AcceptInvalid

class _AcceptProperty:
@overload
def __get__(self, __obj: None, __type: type | None = ...) -> property: ...
def __get__(self, obj: None, type: type | None = ..., /) -> property: ...
@overload
def __get__(self, __obj: Any, __type: type | None = ...) -> AcceptNoHeader | AcceptValidHeader | AcceptInvalidHeader: ...
def __get__(self, obj: Any, type: type | None = ..., /) -> AcceptNoHeader | AcceptValidHeader | AcceptInvalidHeader: ...
@overload
def __set__(self, __obj: Any, __value: str | None) -> None: ...
def __set__(self, obj: Any, value: str | None, /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: AcceptNoHeader | AcceptValidHeader | AcceptInvalidHeader) -> None: ...
def __set__(self, obj: Any, value: AcceptNoHeader | AcceptValidHeader | AcceptInvalidHeader, /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: SupportsItems[str, float | tuple[float, str]]) -> None: ...
def __set__(self, obj: Any, value: SupportsItems[str, float | tuple[float, str]], /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: _ListOrTuple[str | tuple[str, float, str] | list[Any]]) -> None: ...
def __delete__(self, __obj: Any) -> None: ...
def __set__(self, obj: Any, value: _ListOrTuple[str | tuple[str, float, str] | list[Any]], /) -> None: ...
def __delete__(self, obj: Any, /) -> None: ...

def accept_property() -> _AcceptProperty: ...

Expand Down Expand Up @@ -221,22 +221,22 @@ def create_accept_charset_header(header_value: str) -> AcceptCharsetValidHeader

class _AcceptCharsetProperty:
@overload
def __get__(self, __obj: None, __type: type | None = ...) -> property: ...
def __get__(self, obj: None, type: type | None = ..., /) -> property: ...
@overload
def __get__(
self, __obj: Any, __type: type | None = ...
self, obj: Any, type: type | None = ..., /
) -> AcceptCharsetNoHeader | AcceptCharsetValidHeader | AcceptCharsetInvalidHeader: ...
@overload
def __set__(self, __obj: Any, __value: str | None) -> None: ...
def __set__(self, obj: Any, value: str | None, /) -> None: ...
@overload
def __set__(
self, __obj: Any, __value: AcceptCharsetNoHeader | AcceptCharsetValidHeader | AcceptCharsetInvalidHeader
self, obj: Any, value: AcceptCharsetNoHeader | AcceptCharsetValidHeader | AcceptCharsetInvalidHeader, /
) -> None: ...
@overload
def __set__(self, __obj: Any, __value: SupportsItems[str, float]) -> None: ...
def __set__(self, obj: Any, value: SupportsItems[str, float], /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: _ListOrTuple[str | tuple[str, float] | list[Any]]) -> None: ...
def __delete__(self, __obj: Any) -> None: ...
def __set__(self, obj: Any, value: _ListOrTuple[str | tuple[str, float] | list[Any]], /) -> None: ...
def __delete__(self, obj: Any, /) -> None: ...

def accept_charset_property() -> _AcceptCharsetProperty: ...

Expand Down Expand Up @@ -336,22 +336,22 @@ def create_accept_encoding_header(header_value: str) -> AcceptEncodingValidHeade

class _AcceptEncodingProperty:
@overload
def __get__(self, __obj: None, __type: type | None = ...) -> property: ...
def __get__(self, obj: None, type: type | None = ..., /) -> property: ...
@overload
def __get__(
self, __obj: Any, __type: type | None = ...
self, obj: Any, type: type | None = ..., /
) -> AcceptEncodingNoHeader | AcceptEncodingValidHeader | AcceptEncodingInvalidHeader: ...
@overload
def __set__(self, __obj: Any, __value: str | None) -> None: ...
def __set__(self, obj: Any, value: str | None, /) -> None: ...
@overload
def __set__(
self, __obj: Any, __value: AcceptEncodingNoHeader | AcceptEncodingValidHeader | AcceptEncodingInvalidHeader
self, obj: Any, value: AcceptEncodingNoHeader | AcceptEncodingValidHeader | AcceptEncodingInvalidHeader, /
) -> None: ...
@overload
def __set__(self, __obj: Any, __value: SupportsItems[str, float]) -> None: ...
def __set__(self, obj: Any, value: SupportsItems[str, float], /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: _ListOrTuple[str | tuple[str, float] | list[Any]]) -> None: ...
def __delete__(self, __obj: Any) -> None: ...
def __set__(self, obj: Any, value: _ListOrTuple[str | tuple[str, float] | list[Any]], /) -> None: ...
def __delete__(self, obj: Any, /) -> None: ...

def accept_encoding_property() -> _AcceptEncodingProperty: ...

Expand Down Expand Up @@ -483,21 +483,21 @@ def create_accept_language_header(header_value: str) -> AcceptLanguageValidHeade

class _AcceptLanguageProperty:
@overload
def __get__(self, __obj: None, __type: type | None = ...) -> property: ...
def __get__(self, obj: None, type: type | None = ..., /) -> property: ...
@overload
def __get__(
self, __obj: Any, __type: type | None = ...
self, obj: Any, type: type | None = ..., /
) -> AcceptLanguageNoHeader | AcceptLanguageValidHeader | AcceptLanguageInvalidHeader: ...
@overload
def __set__(self, __obj: Any, __value: str | None) -> None: ...
def __set__(self, obj: Any, value: str | None, /) -> None: ...
@overload
def __set__(
self, __obj: Any, __value: AcceptLanguageNoHeader | AcceptLanguageValidHeader | AcceptLanguageInvalidHeader
self, obj: Any, value: AcceptLanguageNoHeader | AcceptLanguageValidHeader | AcceptLanguageInvalidHeader, /
) -> None: ...
@overload
def __set__(self, __obj: Any, __value: SupportsItems[str, float]) -> None: ...
def __set__(self, obj: Any, value: SupportsItems[str, float], /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: _ListOrTuple[str | tuple[str, float] | list[Any]]) -> None: ...
def __delete__(self, __obj: Any) -> None: ...
def __set__(self, obj: Any, value: _ListOrTuple[str | tuple[str, float] | list[Any]], /) -> None: ...
def __delete__(self, obj: Any, /) -> None: ...

def accept_language_property() -> _AcceptLanguageProperty: ...
4 changes: 2 additions & 2 deletions stubs/WebOb/webob/cookies.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ _T = TypeVar("_T")
_SameSitePolicy: TypeAlias = Literal["Strict", "Lax", "None", "strict", "lax", "none"]

class _Serializer(Protocol):
def loads(self, __appstruct: Any) -> bytes: ...
def dumps(self, __bstruct: bytes) -> Any: ...
def loads(self, appstruct: Any, /) -> bytes: ...
def dumps(self, bstruct: bytes, /) -> Any: ...

class RequestCookies(MutableMapping[str, str]):
def __init__(self, environ: WSGIEnvironment) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/WebOb/webob/dec.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ class _unbound_wsgify(wsgify[_RequestT_contra, _P], Generic[_RequestT_contra, _P
@overload
def __call__(self, __self: _S, func: _RequestHandler[_RequestT_contra, _P], /) -> Self: ...
@overload
def __call__(self, __self: _S, req: _RequestT_contra) -> _AnyResponse: ...
def __call__(self, __self: _S, /, req: _RequestT_contra) -> _AnyResponse: ...
@overload
def __call__(self, __self: _S, req: _RequestT_contra, *args: _P.args, **kw: _P.kwargs) -> _AnyResponse: ...
def __call__(self, __self: _S, /, req: _RequestT_contra, *args: _P.args, **kw: _P.kwargs) -> _AnyResponse: ...

class _UnboundMiddleware(Generic[_RequestT_contra, _AppT_contra, _P]):
wrapper_class: type[wsgify[_RequestT_contra, Concatenate[_AppT_contra, _P]]]
Expand Down
8 changes: 4 additions & 4 deletions stubs/WebOb/webob/descriptors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ _ContentRangeParams: TypeAlias = (

class _AsymmetricProperty(Generic[_GetterReturnType, _SetterValueType]):
@overload
def __get__(self, __obj: None, __type: type | None = ...) -> property: ...
def __get__(self, obj: None, type: type | None = ..., /) -> property: ...
@overload
def __get__(self, __obj: Any, __type: type | None = ...) -> _GetterReturnType: ...
def __set__(self, __obj: Any, __value: _SetterValueType) -> None: ...
def __get__(self, obj: Any, type: type | None = ..., /) -> _GetterReturnType: ...
def __set__(self, obj: Any, value: _SetterValueType, /) -> None: ...

class _AsymmetricPropertyWithDelete(_AsymmetricProperty[_GetterReturnType, _SetterValueType]):
def __delete__(self, __obj: Any) -> None: ...
def __delete__(self, obj: Any, /) -> None: ...

class _SymmetricProperty(_AsymmetricProperty[_T, _T]): ...
class _SymmetricPropertyWithDelete(_AsymmetricPropertyWithDelete[_T, _T]): ...
Expand Down
10 changes: 5 additions & 5 deletions stubs/WebOb/webob/etag.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ _ETag: TypeAlias = _AnyETag | _NoETag | ETagMatcher

class _ETagProperty:
@overload
def __get__(self, __obj: None, __type: type | None = ...) -> property: ...
def __get__(self, obj: None, type: type | None = ..., /) -> property: ...
@overload
def __get__(self, __obj: Any, __type: type | None = ...) -> _ETag: ...
def __get__(self, obj: Any, type: type | None = ..., /) -> _ETag: ...
@overload
def __set__(self, __obj: Any, __value: str | None) -> None: ...
def __set__(self, obj: Any, value: str | None, /) -> None: ...
@overload
def __set__(self, __obj: Any, __value: _ETag) -> None: ...
def __delete__(self, __obj: Any) -> None: ...
def __set__(self, obj: Any, value: _ETag, /) -> None: ...
def __delete__(self, obj: Any, /) -> None: ...

def etag_property(key: str, default: _ETag, rfc_section: str, strong: bool = True) -> _ETagProperty: ...

Expand Down
6 changes: 3 additions & 3 deletions stubs/WebOb/webob/multidict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ _VT = TypeVar("_VT")

class MultiDict(MutableMapping[_KT, _VT]):
@overload
def __init__(self, __m: SupportsItems[_KT, _VT], **kwargs: _VT) -> None: ...
def __init__(self, m: SupportsItems[_KT, _VT], /, **kwargs: _VT) -> None: ...
@overload
def __init__(self, __m: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def __init__(self, m: Iterable[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ...
@overload
def __init__(self, **kwargs: _VT) -> None: ...
@classmethod
Expand Down Expand Up @@ -46,7 +46,7 @@ class MultiDict(MutableMapping[_KT, _VT]):
def pop(self, key: _KT, default: _T) -> _VT | _T: ...
def popitem(self) -> tuple[_KT, _VT]: ...
@overload # type: ignore[override]
def update(self, __m: Collection[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def update(self, m: Collection[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ...
@overload
def update(self, **kwargs: _VT) -> None: ...
@overload
Expand Down
6 changes: 3 additions & 3 deletions stubs/aiofiles/aiofiles/tempfile/temptypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class AsyncSpooledTemporaryFile(AsyncBase[_T]):
async def flush(self) -> None: ...
async def isatty(self) -> bool: ...
# All must return `AnyStr`:
async def read(self, __n: int = ...) -> Incomplete: ...
async def readline(self, __limit: int | None = ...) -> Incomplete: ...
async def readlines(self, __hint: int = ...) -> list[Incomplete]: ...
async def read(self, n: int = ..., /) -> Incomplete: ...
async def readline(self, limit: int | None = ..., /) -> Incomplete: ...
async def readlines(self, hint: int = ..., /) -> list[Incomplete]: ...
# ---
async def seek(self, offset: int, whence: int = ...) -> int: ...
async def tell(self) -> int: ...
Expand Down
Loading
Loading