From e3d4bdc91a792bcef5d8eae2c1abab3d4ba27541 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Jul 2022 08:23:24 +0100 Subject: [PATCH] Third-party stubs: enforce CamelCase for type alias names (#8256) Co-authored-by: Jelle Zijlstra --- stubs/SQLAlchemy/sqlalchemy/sql/base.pyi | 3 +- .../sqlalchemy/util/_collections.pyi | 8 +++-- .../sqlalchemy/util/_concurrency_py3k.pyi | 4 +-- stubs/boto/boto/utils.pyi | 10 +++--- stubs/caldav/caldav/objects.pyi | 4 +-- stubs/html5lib/html5lib/_tokenizer.pyi | 3 +- stubs/psutil/psutil/__init__.pyi | 5 ++- stubs/psycopg2/psycopg2/_psycopg.pyi | 10 +++--- .../dateutil/relativedelta.pyi | 6 ++-- stubs/python-dateutil/dateutil/rrule.pyi | 4 +-- stubs/typed-ast/typed_ast/ast27.pyi | 28 ++++++++-------- stubs/typed-ast/typed_ast/ast3.pyi | 32 +++++++++---------- stubs/waitress/waitress/wasyncore.pyi | 20 ++++++------ 13 files changed, 69 insertions(+), 68 deletions(-) diff --git a/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi b/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi index fd7d08865..bcfad9f2c 100644 --- a/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi @@ -5,6 +5,7 @@ from typing import Any, ClassVar from .. import util from ..util import HasMemoized, hybridmethod, memoized_property from . import roles +from .elements import ColumnElement from .traversals import ( HasCacheKey as HasCacheKey, HasCopyInternals as HasCopyInternals, @@ -151,7 +152,7 @@ class ImmutableColumnCollection(util.ImmutableContainer, ColumnCollection): extend: Any remove: Any -class ColumnSet(util.ordered_column_set): +class ColumnSet(util.ordered_column_set[ColumnElement[Any]]): def contains_column(self, col): ... def extend(self, cols) -> None: ... def __add__(self, other): ... diff --git a/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi b/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi index 47e97b304..1a8acae9c 100644 --- a/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi @@ -2,10 +2,8 @@ import collections.abc from _typeshed import Self, SupportsKeysAndGetItem from collections.abc import Callable, Iterable, Iterator, Mapping from typing import Any, Generic, NoReturn, TypeVar, overload -from typing_extensions import TypeAlias from ..cimmutabledict import immutabledict as immutabledict -from ..sql.elements import ColumnElement _KT = TypeVar("_KT") _VT = TypeVar("_VT") @@ -163,7 +161,11 @@ class WeakPopulateDict(dict[Any, Any]): column_set = set column_dict = dict -ordered_column_set: TypeAlias = OrderedSet[ColumnElement[Any]] +# Ignore Y026, this isn't a type alias. +# We have to do `ordered_column_set = OrderedSet[_T] +# instead of `ordered_column_set = OrderedSet`, +# or pyright complains +ordered_column_set = OrderedSet[_T] # noqa: Y026 def unique_list(seq: Iterable[_T], hashfunc: Callable[[_T], Any] | None = ...) -> list[_T]: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi b/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi index 2cf494840..702ef9ea1 100644 --- a/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi @@ -5,11 +5,11 @@ from typing_extensions import TypeAlias from .langhelpers import memoized_property -_greenlet: TypeAlias = Any # actually greenlet.greenlet +_Greenlet: TypeAlias = Any # actually greenlet.greenlet def is_exit_exception(e): ... -class _AsyncIoGreenlet(_greenlet): +class _AsyncIoGreenlet(_Greenlet): driver: Any gr_context: Any def __init__(self, fn, driver) -> None: ... diff --git a/stubs/boto/boto/utils.pyi b/stubs/boto/boto/utils.pyi index d6e7e5e44..f9ce83d48 100644 --- a/stubs/boto/boto/utils.pyi +++ b/stubs/boto/boto/utils.pyi @@ -96,14 +96,14 @@ class LRUCache(dict[_KT, _VT]): def __init__(self, capacity: int) -> None: ... # This exists to work around Password.str's name shadowing the str type -_str: TypeAlias = str +_Str: TypeAlias = str class Password: hashfunc: Callable[[bytes], _Hash] - str: _str | None - def __init__(self, str: _str | None = ..., hashfunc: Callable[[bytes], _Hash] | None = ...) -> None: ... - def set(self, value: bytes | _str) -> None: ... - def __eq__(self, other: _str | bytes | None) -> bool: ... # type: ignore[override] + str: _Str | None + def __init__(self, str: _Str | None = ..., hashfunc: Callable[[bytes], _Hash] | None = ...) -> None: ... + def set(self, value: bytes | _Str) -> None: ... + def __eq__(self, other: _Str | bytes | None) -> bool: ... # type: ignore[override] def __len__(self) -> int: ... def notify( diff --git a/stubs/caldav/caldav/objects.pyi b/stubs/caldav/caldav/objects.pyi index d30ee12d3..903f98a0c 100644 --- a/stubs/caldav/caldav/objects.pyi +++ b/stubs/caldav/caldav/objects.pyi @@ -13,7 +13,7 @@ from .lib.url import URL _CC = TypeVar("_CC", bound=CalendarObjectResource) -_vCalAddress: TypeAlias = Any # actually icalendar.vCalAddress +_VCalAddress: TypeAlias = Any # actually icalendar.vCalAddress class DAVObject: id: str | None @@ -58,7 +58,7 @@ class Principal(DAVObject): self, name: str | None = ..., cal_id: str | None = ..., supported_calendar_component_set: Any | None = ... ) -> Calendar: ... def calendar(self, name: str | None = ..., cal_id: str | None = ...) -> Calendar: ... - def get_vcal_address(self) -> _vCalAddress: ... + def get_vcal_address(self) -> _VCalAddress: ... calendar_home_set: CalendarSet # can also be set to anything URL.objectify() accepts def freebusy_request(self, dtstart, dtend, attendees): ... def calendar_user_address_set(self) -> list[str]: ... diff --git a/stubs/html5lib/html5lib/_tokenizer.pyi b/stubs/html5lib/html5lib/_tokenizer.pyi index 158218c6f..22c471637 100644 --- a/stubs/html5lib/html5lib/_tokenizer.pyi +++ b/stubs/html5lib/html5lib/_tokenizer.pyi @@ -1,8 +1,7 @@ from typing import Any -from typing_extensions import TypeAlias entitiesTrie: Any -attributeMap: TypeAlias = dict[Any, Any] +attributeMap = dict class HTMLTokenizer: stream: Any diff --git a/stubs/psutil/psutil/__init__.pyi b/stubs/psutil/psutil/__init__.pyi index 4c62a8899..868dc1b66 100644 --- a/stubs/psutil/psutil/__init__.pyi +++ b/stubs/psutil/psutil/__init__.pyi @@ -3,7 +3,6 @@ from _typeshed import Self from collections.abc import Callable, Iterable, Iterator from contextlib import AbstractContextManager from typing import Any -from typing_extensions import TypeAlias from ._common import ( AIX as AIX, @@ -109,8 +108,8 @@ elif sys.platform == "darwin": elif sys.platform == "win32": from ._pswindows import pfullmem, pmem else: - pmem: TypeAlias = Any - pfullmem: TypeAlias = Any + class pmem(Any): ... + class pfullmem(Any): ... if sys.platform == "linux": PROCFS_PATH: str diff --git a/stubs/psycopg2/psycopg2/_psycopg.pyi b/stubs/psycopg2/psycopg2/_psycopg.pyi index e391dd173..45d62c52d 100644 --- a/stubs/psycopg2/psycopg2/_psycopg.pyi +++ b/stubs/psycopg2/psycopg2/_psycopg.pyi @@ -112,7 +112,7 @@ class cursor: def __iter__(self: Self) -> Self: ... def __next__(self) -> tuple[Any, ...]: ... -_cursor: TypeAlias = cursor +_Cursor: TypeAlias = cursor class AsIs: adapted: Any @@ -246,7 +246,7 @@ class Diagnostics: def __init__(self, __err: Error) -> None: ... class Error(Exception): - cursor: _cursor | None + cursor: _Cursor | None diag: Diagnostics pgcode: str | None pgerror: str | None @@ -357,7 +357,7 @@ class Xid: def __getitem__(self, __index): ... def __len__(self): ... -_T_cur = TypeVar("_T_cur", bound=_cursor) +_T_cur = TypeVar("_T_cur", bound=cursor) class connection: DataError: Any @@ -377,7 +377,7 @@ class connection: def binary_types(self) -> Any: ... @property def closed(self) -> int: ... - cursor_factory: Callable[..., _cursor] + cursor_factory: Callable[..., _Cursor] @property def dsn(self) -> str: ... @property @@ -415,7 +415,7 @@ class connection: def close(self) -> None: ... def commit(self) -> None: ... @overload - def cursor(self, name: str | bytes | None = ..., *, withhold: bool = ..., scrollable: bool | None = ...) -> _cursor: ... + def cursor(self, name: str | bytes | None = ..., *, withhold: bool = ..., scrollable: bool | None = ...) -> _Cursor: ... @overload def cursor( self, diff --git a/stubs/python-dateutil/dateutil/relativedelta.pyi b/stubs/python-dateutil/dateutil/relativedelta.pyi index 70f107722..20f7c6833 100644 --- a/stubs/python-dateutil/dateutil/relativedelta.pyi +++ b/stubs/python-dateutil/dateutil/relativedelta.pyi @@ -9,7 +9,7 @@ from ._common import weekday _SelfT = TypeVar("_SelfT", bound=relativedelta) _DateT = TypeVar("_DateT", date, datetime) # Work around attribute and type having the same name. -_weekday: TypeAlias = weekday +_Weekday: TypeAlias = weekday MO: weekday TU: weekday @@ -30,7 +30,7 @@ class relativedelta: microseconds: int year: int | None month: int | None - weekday: _weekday | None + weekday: _Weekday | None day: int | None hour: int | None minute: int | None @@ -52,7 +52,7 @@ class relativedelta: year: int | None = ..., month: int | None = ..., day: int | None = ..., - weekday: int | _weekday | None = ..., + weekday: int | _Weekday | None = ..., yearday: int | None = ..., nlyearday: int | None = ..., hour: int | None = ..., diff --git a/stubs/python-dateutil/dateutil/rrule.pyi b/stubs/python-dateutil/dateutil/rrule.pyi index 05b0f94bb..7acf76454 100644 --- a/stubs/python-dateutil/dateutil/rrule.pyi +++ b/stubs/python-dateutil/dateutil/rrule.pyi @@ -84,7 +84,7 @@ class _iterinfo: def mtimeset(self, hour, minute, second): ... def stimeset(self, hour, minute, second): ... -_rrule: TypeAlias = rrule +_RRule: TypeAlias = rrule class rruleset(rrulebase): class _genitem: @@ -100,7 +100,7 @@ class rruleset(rrulebase): def __ne__(self, other): ... def __init__(self, cache: bool = ...) -> None: ... - def rrule(self, rrule: _rrule): ... + def rrule(self, rrule: _RRule): ... def rdate(self, rdate): ... def exrule(self, exrule): ... def exdate(self, exdate): ... diff --git a/stubs/typed-ast/typed_ast/ast27.pyi b/stubs/typed-ast/typed_ast/ast27.pyi index 8c8a1f8b8..4faf50e66 100644 --- a/stubs/typed-ast/typed_ast/ast27.pyi +++ b/stubs/typed-ast/typed_ast/ast27.pyi @@ -24,7 +24,7 @@ PyCF_ONLY_AST: int # ast classes -_identifier: TypeAlias = str +_Identifier: TypeAlias = str class AST: _attributes: tuple[str, ...] @@ -55,14 +55,14 @@ class stmt(AST): col_offset: int class FunctionDef(stmt): - name: _identifier + name: _Identifier args: arguments body: list[stmt] decorator_list: list[expr] type_comment: str | None class ClassDef(stmt): - name: _identifier + name: _Identifier bases: list[expr] body: list[stmt] decorator_list: list[expr] @@ -133,7 +133,7 @@ class Import(stmt): names: list[alias] class ImportFrom(stmt): - module: _identifier | None + module: _Identifier | None names: list[alias] level: int | None @@ -143,7 +143,7 @@ class Exec(stmt): locals: expr | None class Global(stmt): - names: list[_identifier] + names: list[_Identifier] class Expr(stmt): value: expr @@ -153,7 +153,7 @@ class Break(stmt): ... class Continue(stmt): ... class slice(AST): ... -_slice: TypeAlias = slice # this lets us type the variable named 'slice' below +_Slice: TypeAlias = slice # this lets us type the variable named 'slice' below class Slice(slice): lower: expr | None @@ -245,16 +245,16 @@ class Str(expr): class Attribute(expr): value: expr - attr: _identifier + attr: _Identifier ctx: expr_context class Subscript(expr): value: expr - slice: _slice + slice: _Slice ctx: expr_context class Name(expr): - id: _identifier + id: _Identifier ctx: expr_context class List(expr): @@ -319,18 +319,18 @@ class ExceptHandler(AST): class arguments(AST): args: list[expr] - vararg: _identifier | None - kwarg: _identifier | None + vararg: _Identifier | None + kwarg: _Identifier | None defaults: list[expr] type_comments: list[str | None] class keyword(AST): - arg: _identifier + arg: _Identifier value: expr class alias(AST): - name: _identifier - asname: _identifier | None + name: _Identifier + asname: _Identifier | None class TypeIgnore(AST): lineno: int diff --git a/stubs/typed-ast/typed_ast/ast3.pyi b/stubs/typed-ast/typed_ast/ast3.pyi index 72cc25c9d..ab941d388 100644 --- a/stubs/typed-ast/typed_ast/ast3.pyi +++ b/stubs/typed-ast/typed_ast/ast3.pyi @@ -24,7 +24,7 @@ PyCF_ONLY_AST: int # ast classes -_identifier: TypeAlias = str +_Identifier: TypeAlias = str class AST: _attributes: tuple[str, ...] @@ -55,7 +55,7 @@ class stmt(AST): col_offset: int class FunctionDef(stmt): - name: _identifier + name: _Identifier args: arguments body: list[stmt] decorator_list: list[expr] @@ -63,7 +63,7 @@ class FunctionDef(stmt): type_comment: str | None class AsyncFunctionDef(stmt): - name: _identifier + name: _Identifier args: arguments body: list[stmt] decorator_list: list[expr] @@ -71,7 +71,7 @@ class AsyncFunctionDef(stmt): type_comment: str | None class ClassDef(stmt): - name: _identifier + name: _Identifier bases: list[expr] keywords: list[keyword] body: list[stmt] @@ -151,15 +151,15 @@ class Import(stmt): names: list[alias] class ImportFrom(stmt): - module: _identifier | None + module: _Identifier | None names: list[alias] level: int | None class Global(stmt): - names: list[_identifier] + names: list[_Identifier] class Nonlocal(stmt): - names: list[_identifier] + names: list[_Identifier] class Expr(stmt): value: expr @@ -169,7 +169,7 @@ class Break(stmt): ... class Continue(stmt): ... class slice(AST): ... -_slice: TypeAlias = slice # this lets us type the variable named 'slice' below +_Slice: TypeAlias = slice # this lets us type the variable named 'slice' below class Slice(slice): lower: expr | None @@ -276,12 +276,12 @@ class Ellipsis(expr): ... class Attribute(expr): value: expr - attr: _identifier + attr: _Identifier ctx: expr_context class Subscript(expr): value: expr - slice: _slice + slice: _Slice ctx: expr_context class Starred(expr): @@ -289,7 +289,7 @@ class Starred(expr): ctx: expr_context class Name(expr): - id: _identifier + id: _Identifier ctx: expr_context class List(expr): @@ -349,7 +349,7 @@ class comprehension(AST): class ExceptHandler(AST): type: expr | None - name: _identifier | None + name: _Identifier | None body: list[stmt] lineno: int col_offset: int @@ -363,19 +363,19 @@ class arguments(AST): defaults: list[expr] class arg(AST): - arg: _identifier + arg: _Identifier annotation: expr | None lineno: int col_offset: int type_comment: str | None class keyword(AST): - arg: _identifier | None + arg: _Identifier | None value: expr class alias(AST): - name: _identifier - asname: _identifier | None + name: _Identifier + asname: _Identifier | None class withitem(AST): context_expr: expr diff --git a/stubs/waitress/waitress/wasyncore.pyi b/stubs/waitress/waitress/wasyncore.pyi index f89ed9677..0338799fe 100644 --- a/stubs/waitress/waitress/wasyncore.pyi +++ b/stubs/waitress/waitress/wasyncore.pyi @@ -7,7 +7,7 @@ from typing_extensions import TypeAlias from . import compat as compat, utilities as utilities -_socket: TypeAlias = socket +_Socket: TypeAlias = socket socket_map: Mapping[int, socket] map: Mapping[int, socket] @@ -35,20 +35,20 @@ class dispatcher: ignore_log_types: frozenset[Any] logger: Logger = ... compact_traceback: Callable[[], tuple[tuple[str, str, str], BaseException, BaseException, str]] = ... - socket: _socket | None = ... - def __init__(self, sock: _socket | None = ..., map: Mapping[int, _socket] | None = ...) -> None: ... - def add_channel(self, map: Mapping[int, _socket] | None = ...) -> None: ... - def del_channel(self, map: Mapping[int, _socket] | None = ...) -> None: ... + socket: _Socket | None = ... + def __init__(self, sock: _Socket | None = ..., map: Mapping[int, _Socket] | None = ...) -> None: ... + def add_channel(self, map: Mapping[int, _Socket] | None = ...) -> None: ... + def del_channel(self, map: Mapping[int, _Socket] | None = ...) -> None: ... family_and_type: tuple[int, int] = ... def create_socket(self, family: int = ..., type: int = ...) -> None: ... - def set_socket(self, sock: _socket, map: Mapping[int, _socket] | None = ...) -> None: ... + def set_socket(self, sock: _Socket, map: Mapping[int, _Socket] | None = ...) -> None: ... def set_reuse_addr(self) -> None: ... def readable(self) -> bool: ... def writable(self) -> bool: ... def listen(self, num: int) -> None: ... def bind(self, addr: tuple[str, int]) -> None: ... def connect(self, address: tuple[str, int]) -> None: ... - def accept(self) -> tuple[_socket, tuple[str, int]] | None: ... + def accept(self) -> tuple[_Socket, tuple[str, int]] | None: ... def send(self, data: bytes, do_close: bool = ...) -> int: ... def recv(self, buffer_size: int) -> bytes: ... def close(self) -> None: ... @@ -64,7 +64,7 @@ class dispatcher: def handle_write(self) -> None: ... def handle_connect(self) -> None: ... def handle_accept(self) -> None: ... - def handle_accepted(self, sock: _socket, addr: Any) -> None: ... + def handle_accepted(self, sock: _Socket, addr: Any) -> None: ... def handle_close(self) -> None: ... class dispatcher_with_send(dispatcher): @@ -91,6 +91,6 @@ class file_wrapper: class file_dispatcher(dispatcher): connected: bool = ... - def __init__(self, fd: BytesIO, map: Mapping[int, _socket] | None = ...) -> None: ... - socket: _socket = ... + def __init__(self, fd: BytesIO, map: Mapping[int, _Socket] | None = ...) -> None: ... + socket: _Socket = ... def set_file(self, fd: BytesIO) -> None: ...