From 9443ab1283209cdb1bb4ff9e486e63233795f3f4 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 26 May 2022 12:14:13 +0100 Subject: [PATCH 1/3] Third-party stubs: fix several fictitious type aliases --- stubs/Pillow/@tests/stubtest_allowlist.txt | 2 ++ stubs/Pillow/PIL/ImageQt.pyi | 6 ++-- .../SQLAlchemy/sqlalchemy/ext/mypy/names.pyi | 18 ++++++------ stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi | 24 ++++++++-------- .../google/cloud/ndb/model.pyi | 6 ++-- stubs/ldap3/ldap3/utils/asn1.pyi | 6 ++-- stubs/python-jose/jose/backends/_asn1.pyi | 9 +++--- stubs/requests/requests/adapters.pyi | 5 ++-- stubs/requests/requests/utils.pyi | 1 - stubs/setuptools/pkg_resources/__init__.pyi | 6 ++-- stubs/typed-ast/typed_ast/ast27.pyi | 24 ++++++++-------- stubs/typed-ast/typed_ast/ast3.pyi | 28 +++++++++---------- stubs/urllib3/urllib3/connection.pyi | 3 -- stubs/waitress/waitress/compat.pyi | 3 -- 14 files changed, 68 insertions(+), 73 deletions(-) diff --git a/stubs/Pillow/@tests/stubtest_allowlist.txt b/stubs/Pillow/@tests/stubtest_allowlist.txt index b0cdde03aa75..3e34ae14e95c 100644 --- a/stubs/Pillow/@tests/stubtest_allowlist.txt +++ b/stubs/Pillow/@tests/stubtest_allowlist.txt @@ -1,4 +1,6 @@ PIL.FpxImagePlugin PIL.ImageQt.ImageQt +PIL.ImageQt.QImage # Does exist at runtime usually, but stubtest can't see it +PIL.ImageQt.QPixmap # Does exist at runtime usually, but stubtest can't see it PIL.MicImagePlugin PIL.WmfImagePlugin.WmfHandler diff --git a/stubs/Pillow/PIL/ImageQt.pyi b/stubs/Pillow/PIL/ImageQt.pyi index b223bba1455d..47283703386e 100644 --- a/stubs/Pillow/PIL/ImageQt.pyi +++ b/stubs/Pillow/PIL/ImageQt.pyi @@ -1,10 +1,10 @@ from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .Image import Image -QImage = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui -QPixmap = Any +QImage: TypeAlias = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui +QPixmap: TypeAlias = Any qt_versions: Any qt_is_installed: bool diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi index f3c4b45c4e48..b6a992fb132e 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi @@ -1,16 +1,16 @@ from typing import Any +from typing_extensions import TypeAlias from ...util import symbol -ClassDef = Any # from mypy.nodes -Expression = Any # from mypy.nodes -MemberExpr = Any # from mypy.nodes -NameExpr = Any # from mypy.nodes -SymbolNode = Any # from mypy.nodes -TypeInfo = Any # from mypy.nodes -StrExpr = Any # from mypy.nodes -SemanticAnalyzerPluginInterface = Any # from mypy.plugin -UnboundType = Any # from mypy.types +ClassDef: TypeAlias = Any # from mypy.nodes +Expression: TypeAlias = Any # from mypy.nodes +MemberExpr: TypeAlias = Any # from mypy.nodes +NameExpr: TypeAlias = Any # from mypy.nodes +SymbolNode: TypeAlias = Any # from mypy.nodes +TypeInfo: TypeAlias = Any # from mypy.nodes +SemanticAnalyzerPluginInterface: TypeAlias = Any # from mypy.plugin +UnboundType: TypeAlias = Any # from mypy.types COLUMN: symbol RELATIONSHIP: symbol diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi index 73f16b6b265f..9c453401b42b 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi @@ -1,18 +1,18 @@ from collections.abc import Iterable, Iterator from typing import Any, TypeVar, overload +from typing_extensions import TypeAlias -CallExpr = Any # from mypy.nodes -Context = Any # from mypy.nodes -Expression = Any # from mypy.nodes -JsonDict = Any # from mypy.nodes -NameExpr = Any # from mypy.nodes -Statement = Any # from mypy.nodes -TypeInfo = Any # from mypy.nodes -AttributeContext = Any # from mypy.plugin -ClassDefContext = Any # from mypy.plugin -DynamicClassDefContext = Any # from mypy.plugin -SemanticAnalyzerPluginInterface = Any # from mypy.plugin -Type = Any # from mypy.types +CallExpr: TypeAlias = Any # from mypy.nodes +Context: TypeAlias = Any # from mypy.nodes +Expression: TypeAlias = Any # from mypy.nodes +JsonDict: TypeAlias = Any # from mypy.nodes +NameExpr: TypeAlias = Any # from mypy.nodes +Statement: TypeAlias = Any # from mypy.nodes +TypeInfo: TypeAlias = Any # from mypy.nodes +ClassDefContext: TypeAlias = Any # from mypy.plugin +DynamicClassDefContext: TypeAlias = Any # from mypy.plugin +SemanticAnalyzerPluginInterface: TypeAlias = Any # from mypy.plugin +Type: TypeAlias = Any # from mypy.types _TArgType = TypeVar("_TArgType", bound=CallExpr | NameExpr) diff --git a/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi b/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi index c416cd7da994..2f77041315cb 100644 --- a/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi +++ b/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi @@ -24,14 +24,14 @@ class UserNotFoundError(exceptions.Error): ... class _NotEqualMixin: def __ne__(self, other: object) -> bool: ... -DirectionT: TypeAlias = Literal["asc", "desc"] +_Direction: TypeAlias = Literal["asc", "desc"] class IndexProperty(_NotEqualMixin): - def __new__(cls: type[Self], name: str, direction: DirectionT) -> Self: ... + def __new__(cls: type[Self], name: str, direction: _Direction) -> Self: ... @property def name(self) -> str: ... @property - def direction(self) -> DirectionT: ... + def direction(self) -> _Direction: ... def __eq__(self, other: object) -> bool: ... def __hash__(self) -> int: ... diff --git a/stubs/ldap3/ldap3/utils/asn1.pyi b/stubs/ldap3/ldap3/utils/asn1.pyi index 859a9b958630..475514ff14a9 100644 --- a/stubs/ldap3/ldap3/utils/asn1.pyi +++ b/stubs/ldap3/ldap3/utils/asn1.pyi @@ -1,9 +1,9 @@ from typing import Any +from typing_extensions import TypeAlias # Enable when pyasn1 gets stubs: -# from pyasn1.codec.ber.encoder import AbstractItemEncoder, BooleanEncoder -AbstractItemEncoder = Any -BooleanEncoder = Any +# from pyasn1.codec.ber.encoder import AbstractItemEncoder +AbstractItemEncoder: TypeAlias = Any CLASSES: Any diff --git a/stubs/python-jose/jose/backends/_asn1.pyi b/stubs/python-jose/jose/backends/_asn1.pyi index 538872b4a53a..0c01c085891a 100644 --- a/stubs/python-jose/jose/backends/_asn1.pyi +++ b/stubs/python-jose/jose/backends/_asn1.pyi @@ -1,18 +1,19 @@ from typing import Any +from typing_extensions import TypeAlias # Enable when pyasn1 gets stubs: # from pyasn1.type import univ -Sequence = Any +_Sequence: TypeAlias = Any RSA_ENCRYPTION_ASN1_OID: str -class RsaAlgorithmIdentifier(Sequence): +class RsaAlgorithmIdentifier(_Sequence): componentType: Any -class PKCS8PrivateKey(Sequence): +class PKCS8PrivateKey(_Sequence): componentType: Any -class PublicKeyInfo(Sequence): +class PublicKeyInfo(_Sequence): componentType: Any def rsa_private_key_pkcs8_to_pkcs1(pkcs8_key): ... diff --git a/stubs/requests/requests/adapters.pyi b/stubs/requests/requests/adapters.pyi index 1084f3881406..8198d2b9a465 100644 --- a/stubs/requests/requests/adapters.pyi +++ b/stubs/requests/requests/adapters.pyi @@ -6,7 +6,6 @@ from urllib3.util import retry from . import cookies, exceptions, models, structures, utils -PreparedRequest = models.PreparedRequest Response = models.Response PoolManager = poolmanager.PoolManager proxy_from_url = poolmanager.proxy_from_url @@ -40,7 +39,7 @@ class BaseAdapter: def __init__(self) -> None: ... def send( self, - request: PreparedRequest, + request: models.PreparedRequest, stream: bool = ..., timeout: None | float | tuple[float, float] | tuple[float, None] = ..., verify: bool | str = ..., @@ -69,7 +68,7 @@ class HTTPAdapter(BaseAdapter): def proxy_headers(self, proxy): ... def send( self, - request: PreparedRequest, + request: models.PreparedRequest, stream: bool = ..., timeout: None | float | tuple[float, float] | tuple[float, None] = ..., verify: bool | str = ..., diff --git a/stubs/requests/requests/utils.pyi b/stubs/requests/requests/utils.pyi index 51e0563a6184..f7df79732b8f 100644 --- a/stubs/requests/requests/utils.pyi +++ b/stubs/requests/requests/utils.pyi @@ -4,7 +4,6 @@ from typing import Any, AnyStr from . import compat, cookies, exceptions, structures OrderedDict = compat.OrderedDict -RequestsCookieJar = cookies.RequestsCookieJar cookiejar_from_dict = cookies.cookiejar_from_dict CaseInsensitiveDict = structures.CaseInsensitiveDict InvalidURL = exceptions.InvalidURL diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index b7b062e29cd7..726750a8cb3a 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -7,8 +7,8 @@ from collections.abc import Callable, Generator, Iterable, Sequence from typing import IO, Any, TypeVar, overload from typing_extensions import TypeAlias -LegacyVersion: TypeAlias = Any # from packaging.version -Version: TypeAlias = Any # from packaging.version +_LegacyVersion: TypeAlias = Any # from packaging.version +_Version: TypeAlias = Any # from packaging.version _T = TypeVar("_T") _NestedStr: TypeAlias = str | Iterable[str | Iterable[Any]] @@ -262,7 +262,7 @@ empty_provider: EmptyProvider class FileMetadata(EmptyProvider, IResourceProvider): def __init__(self, path_to_pkg_info: str) -> None: ... -def parse_version(v: str) -> Version | LegacyVersion: ... +def parse_version(v: str) -> _Version | _LegacyVersion: ... def yield_lines(strs: _NestedStr) -> Generator[str, None, None]: ... def split_sections(strs: _NestedStr) -> Generator[tuple[str | None, str], None, None]: ... def safe_name(name: str) -> str: ... diff --git a/stubs/typed-ast/typed_ast/ast27.pyi b/stubs/typed-ast/typed_ast/ast27.pyi index de926f0f2ebb..8c8a1f8b89c0 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 = 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 @@ -245,7 +245,7 @@ class Str(expr): class Attribute(expr): value: expr - attr: identifier + attr: _identifier ctx: expr_context class Subscript(expr): @@ -254,7 +254,7 @@ class Subscript(expr): 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 58e2e5f8b9d3..72cc25c9dc5b 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 = 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 @@ -276,7 +276,7 @@ class Ellipsis(expr): ... class Attribute(expr): value: expr - attr: identifier + attr: _identifier ctx: expr_context class Subscript(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/urllib3/urllib3/connection.pyi b/stubs/urllib3/urllib3/connection.pyi index ab90e131128b..02565f183fb9 100644 --- a/stubs/urllib3/urllib3/connection.pyi +++ b/stubs/urllib3/urllib3/connection.pyi @@ -16,7 +16,6 @@ class DummyConnection: ... BaseSSLError = ssl.SSLError ConnectTimeoutError = exceptions.ConnectTimeoutError -SystemTimeWarning = exceptions.SystemTimeWarning SecurityWarning = exceptions.SecurityWarning match_hostname = ssl_match_hostname.match_hostname resolve_cert_reqs = ssl_.resolve_cert_reqs @@ -58,5 +57,3 @@ class VerifiedHTTPSConnection(HTTPSConnection): auto_open: Any is_verified: Any def connect(self): ... - -UnverifiedHTTPSConnection = HTTPSConnection diff --git a/stubs/waitress/waitress/compat.pyi b/stubs/waitress/waitress/compat.pyi index 07757c9fe04d..4c00c6990351 100644 --- a/stubs/waitress/waitress/compat.pyi +++ b/stubs/waitress/waitress/compat.pyi @@ -7,9 +7,6 @@ WIN: bool string_types: tuple[str] integer_types: tuple[int] class_types: tuple[type] -text_type = str -binary_type = bytes -long = int def unquote_bytes_to_wsgi(bytestring: bytes) -> str: ... def text_(s: str, encoding: str = ..., errors: str = ...) -> str: ... From ba62628b93b21677b9868720308df18a64ecddf7 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 26 May 2022 12:22:42 +0100 Subject: [PATCH 2/3] Deleted the wrong thing from `urllib3` --- stubs/urllib3/urllib3/connection.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/urllib3/urllib3/connection.pyi b/stubs/urllib3/urllib3/connection.pyi index 02565f183fb9..f96e1640bcde 100644 --- a/stubs/urllib3/urllib3/connection.pyi +++ b/stubs/urllib3/urllib3/connection.pyi @@ -16,7 +16,7 @@ class DummyConnection: ... BaseSSLError = ssl.SSLError ConnectTimeoutError = exceptions.ConnectTimeoutError -SecurityWarning = exceptions.SecurityWarning +SystemTimeWarning = exceptions.SystemTimeWarning match_hostname = ssl_match_hostname.match_hostname resolve_cert_reqs = ssl_.resolve_cert_reqs resolve_ssl_version = ssl_.resolve_ssl_version From 98d6b6ee066d6029788baed5c18f80efb08b35b7 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 26 May 2022 13:04:20 +0100 Subject: [PATCH 3/3] Try manually pinning protobuf? --- stubs/google-cloud-ndb/@tests/requirements-stubtest.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 stubs/google-cloud-ndb/@tests/requirements-stubtest.txt diff --git a/stubs/google-cloud-ndb/@tests/requirements-stubtest.txt b/stubs/google-cloud-ndb/@tests/requirements-stubtest.txt new file mode 100644 index 000000000000..89cfdc0ca834 --- /dev/null +++ b/stubs/google-cloud-ndb/@tests/requirements-stubtest.txt @@ -0,0 +1 @@ +protobuf==3.20.1