From 4ead5318c6169f38c948abf57cbdd035d04a1e50 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 18 Jan 2023 14:04:56 -0500 Subject: [PATCH 1/8] Manual changes of Any - ClassVar[Any | None] - Missed previous changes due to alias - Manual review of leftover Any unions (`| Any` and `Any |`) --- stubs/PyYAML/yaml/nodes.pyi | 9 +++++---- stubs/PyYAML/yaml/representer.pyi | 6 +++--- .../SQLAlchemy/sqlalchemy/dialects/postgresql/array.pyi | 7 +++++-- stubs/paho-mqtt/paho/mqtt/client.pyi | 5 +++-- stubs/parsimonious/parsimonious/grammar.pyi | 3 ++- stubs/parsimonious/parsimonious/nodes.pyi | 3 ++- stubs/passlib/passlib/utils/handlers.pyi | 2 +- .../google/protobuf/internal/well_known_types.pyi | 6 +++--- stubs/redis/redis/lock.pyi | 8 ++++---- stubs/toml/toml/encoder.pyi | 4 ++-- 10 files changed, 30 insertions(+), 23 deletions(-) diff --git a/stubs/PyYAML/yaml/nodes.pyi b/stubs/PyYAML/yaml/nodes.pyi index 98e61e296c87..2a99dc3ba505 100644 --- a/stubs/PyYAML/yaml/nodes.pyi +++ b/stubs/PyYAML/yaml/nodes.pyi @@ -1,3 +1,4 @@ +from _typeshed import Incomplete from typing import Any, ClassVar from yaml.error import Mark @@ -5,19 +6,19 @@ from yaml.error import Mark class Node: tag: str value: Any - start_mark: Mark | Any - end_mark: Mark | Any + start_mark: Mark | Incomplete + end_mark: Mark | Incomplete def __init__(self, tag: str, value, start_mark: Mark | None, end_mark: Mark | None) -> None: ... class ScalarNode(Node): id: ClassVar[str] - style: str | Any + style: str | Incomplete def __init__( self, tag: str, value, start_mark: Mark | None = ..., end_mark: Mark | None = ..., style: str | None = ... ) -> None: ... class CollectionNode(Node): - flow_style: bool | Any + flow_style: bool | Incomplete def __init__( self, tag: str, value, start_mark: Mark | None = ..., end_mark: Mark | None = ..., flow_style: bool | None = ... ) -> None: ... diff --git a/stubs/PyYAML/yaml/representer.pyi b/stubs/PyYAML/yaml/representer.pyi index f9802d2df7e0..86deea5af651 100644 --- a/stubs/PyYAML/yaml/representer.pyi +++ b/stubs/PyYAML/yaml/representer.pyi @@ -1,5 +1,5 @@ import datetime -from _typeshed import SupportsItems +from _typeshed import Incomplete, SupportsItems from collections.abc import Callable, Iterable, Mapping from types import BuiltinFunctionType, FunctionType, ModuleType from typing import Any, ClassVar, NoReturn, TypeVar @@ -15,12 +15,12 @@ class RepresenterError(YAMLError): ... class BaseRepresenter: yaml_representers: ClassVar[dict[type[Any], Callable[[BaseRepresenter, Any], Node]]] yaml_multi_representers: ClassVar[dict[type[Any], Callable[[BaseRepresenter, Any], Node]]] - default_style: str | Any + default_style: str | Incomplete sort_keys: bool default_flow_style: bool represented_objects: dict[int, Node] object_keeper: list[Any] - alias_key: int | Any + alias_key: int | Incomplete def __init__(self, default_style: str | None = ..., default_flow_style: bool = ..., sort_keys: bool = ...) -> None: ... def represent(self, data) -> None: ... def represent_data(self, data) -> Node: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/dialects/postgresql/array.pyi b/stubs/SQLAlchemy/sqlalchemy/dialects/postgresql/array.pyi index 5bcc21b1c817..fe7c0e8bcb1d 100644 --- a/stubs/SQLAlchemy/sqlalchemy/dialects/postgresql/array.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/dialects/postgresql/array.pyi @@ -1,3 +1,4 @@ +from _typeshed import Incomplete from typing import Any as _Any import sqlalchemy.types as sqltypes @@ -13,7 +14,7 @@ class array(expression.ClauseList, expression.ColumnElement[_Any]): inherit_cache: bool type: _Any def __init__(self, clauses, **kw) -> None: ... - def self_group(self, against: _Any | None = ...): ... + def self_group(self, against: Incomplete | None = ...): ... CONTAINS: _Any CONTAINED_BY: _Any @@ -29,7 +30,9 @@ class ARRAY(sqltypes.ARRAY): as_tuple: _Any dimensions: _Any zero_indexes: _Any - def __init__(self, item_type, as_tuple: bool = ..., dimensions: _Any | None = ..., zero_indexes: bool = ...) -> None: ... + def __init__( + self, item_type, as_tuple: bool = ..., dimensions: Incomplete | None = ..., zero_indexes: bool = ... + ) -> None: ... @property def hashable(self): ... @property diff --git a/stubs/paho-mqtt/paho/mqtt/client.pyi b/stubs/paho-mqtt/paho/mqtt/client.pyi index e2b0a82375a4..3a3b0f1e4bc5 100644 --- a/stubs/paho-mqtt/paho/mqtt/client.pyi +++ b/stubs/paho-mqtt/paho/mqtt/client.pyi @@ -3,6 +3,7 @@ import socket as _socket import ssl as _ssl import time import types +from _typeshed import Incomplete from collections.abc import Callable from typing import Any, Optional, TypeVar from typing_extensions import TypeAlias @@ -16,7 +17,7 @@ ssl: types.ModuleType | None socks: types.ModuleType | None time_func = time.monotonic HAVE_DNS: bool -EAGAIN: int | Any +EAGAIN: int | Incomplete MQTTv31: int MQTTv311: int MQTTv5: int @@ -86,7 +87,7 @@ MQTT_BRIDGE: int MQTT_CLEAN_START_FIRST_ONLY: int sockpair_data: bytes _UserData: TypeAlias = Any -_Socket: TypeAlias = _socket.socket | _ssl.SSLSocket | Any +_Socket: TypeAlias = _socket.socket | _ssl.SSLSocket | Incomplete _Payload: TypeAlias = str | bytes | bytearray | float _ExtraHeader: TypeAlias = dict[str, str] | Callable[[dict[str, str]], dict[str, str]] _OnLog: TypeAlias = Callable[[Client, _UserData, int, str], object] diff --git a/stubs/parsimonious/parsimonious/grammar.pyi b/stubs/parsimonious/parsimonious/grammar.pyi index f686df326c65..ee6dde713471 100644 --- a/stubs/parsimonious/parsimonious/grammar.pyi +++ b/stubs/parsimonious/parsimonious/grammar.pyi @@ -1,4 +1,5 @@ import collections.abc +from _typeshed import Incomplete from collections import OrderedDict from collections.abc import Callable, Mapping from typing import Any, NoReturn @@ -7,7 +8,7 @@ from parsimonious.expressions import _CALLABLE_TYPE, Expression, Literal, Lookah from parsimonious.nodes import Node, NodeVisitor class Grammar(OrderedDict[str, Expression]): - default_rule: Expression | Any + default_rule: Expression | Incomplete def __init__(self, rules: str = ..., **more_rules: Expression | _CALLABLE_TYPE) -> None: ... def default(self, rule_name: str) -> Grammar: ... def parse(self, text: str, pos: int = ...) -> Node: ... diff --git a/stubs/parsimonious/parsimonious/nodes.pyi b/stubs/parsimonious/parsimonious/nodes.pyi index cffd15569870..03aff4a5b00a 100644 --- a/stubs/parsimonious/parsimonious/nodes.pyi +++ b/stubs/parsimonious/parsimonious/nodes.pyi @@ -1,3 +1,4 @@ +from _typeshed import Incomplete from collections.abc import Callable, Iterator, Sequence from re import Match from typing import Any, NoReturn, TypeVar @@ -27,7 +28,7 @@ class RegexNode(Node): class RuleDecoratorMeta(type): ... class NodeVisitor(metaclass=RuleDecoratorMeta): - grammar: Grammar | Any + grammar: Grammar | Incomplete unwrapped_exceptions: tuple[type[BaseException], ...] def visit(self, node: Node) -> Any: ... def generic_visit(self, node: Node, visited_children: Sequence[Any]) -> NoReturn: ... diff --git a/stubs/passlib/passlib/utils/handlers.pyi b/stubs/passlib/passlib/utils/handlers.pyi index b474606b0473..525ed854f297 100644 --- a/stubs/passlib/passlib/utils/handlers.pyi +++ b/stubs/passlib/passlib/utils/handlers.pyi @@ -110,7 +110,7 @@ class HasRounds(GenericHandler): min_desired_rounds: ClassVar[int | None] max_desired_rounds: ClassVar[int | None] default_rounds: ClassVar[int | None] - vary_rounds: ClassVar[Any | None] + vary_rounds: ClassVar[Incomplete | None] rounds: int @classmethod def using( # type: ignore[override] diff --git a/stubs/protobuf/google/protobuf/internal/well_known_types.pyi b/stubs/protobuf/google/protobuf/internal/well_known_types.pyi index 8c1592952c73..f0e17309d747 100644 --- a/stubs/protobuf/google/protobuf/internal/well_known_types.pyi +++ b/stubs/protobuf/google/protobuf/internal/well_known_types.pyi @@ -1,4 +1,4 @@ -from _typeshed import SupportsItems +from _typeshed import Incomplete, SupportsItems from collections.abc import Iterable, Iterator, KeysView, Mapping, Sequence from datetime import datetime, timedelta, tzinfo from typing import Any as tAny @@ -9,7 +9,7 @@ from google.protobuf import struct_pb2 class Any: type_url: tAny = ... value: tAny = ... - def Pack(self, msg: tAny, type_url_prefix: str = ..., deterministic: tAny | None = ...) -> None: ... + def Pack(self, msg: tAny, type_url_prefix: str = ..., deterministic: Incomplete | None = ...) -> None: ... def Unpack(self, msg: tAny) -> bool: ... def TypeName(self) -> str: ... def Is(self, descriptor: tAny) -> bool: ... @@ -60,7 +60,7 @@ class FieldMask: ) -> None: ... class _FieldMaskTree: - def __init__(self, field_mask: tAny | None = ...) -> None: ... + def __init__(self, field_mask: Incomplete | None = ...) -> None: ... def MergeFromFieldMask(self, field_mask: tAny) -> None: ... def AddPath(self, path: tAny): ... def ToFieldMask(self, field_mask: tAny) -> None: ... diff --git a/stubs/redis/redis/lock.pyi b/stubs/redis/redis/lock.pyi index 7d6bc94fa48a..358f33596ea6 100644 --- a/stubs/redis/redis/lock.pyi +++ b/stubs/redis/redis/lock.pyi @@ -1,4 +1,4 @@ -from _typeshed import Self +from _typeshed import Incomplete, Self from types import TracebackType from typing import Any, ClassVar, Protocol @@ -11,9 +11,9 @@ class Lock: LUA_EXTEND_SCRIPT: ClassVar[str] LUA_REACQUIRE_SCRIPT: ClassVar[str] LUA_RELEASE_SCRIPT: ClassVar[str] - lua_extend: ClassVar[Any | None] - lua_reacquire: ClassVar[Any | None] - lua_release: ClassVar[Any | None] + lua_extend: ClassVar[Incomplete | None] + lua_reacquire: ClassVar[Incomplete | None] + lua_release: ClassVar[Incomplete | None] local: _Local def __init__( self, diff --git a/stubs/toml/toml/encoder.pyi b/stubs/toml/toml/encoder.pyi index 992b18e2b23a..3d8adb9b4922 100644 --- a/stubs/toml/toml/encoder.pyi +++ b/stubs/toml/toml/encoder.pyi @@ -17,8 +17,8 @@ class TomlEncoder(Generic[_MappingT]): def __init__(self: TomlEncoder[dict[str, Any]], _dict: type[dict[str, Any]] = ..., preserve: bool = ...) -> None: ... def get_empty_table(self) -> _MappingT: ... def dump_list(self, v: Iterable[object]) -> str: ... - def dump_inline_table(self, section: dict[str, Any] | Any) -> str: ... - def dump_value(self, v: Any) -> str: ... + def dump_inline_table(self, section: object) -> str: ... + def dump_value(self, v: object) -> str: ... def dump_sections(self, o: _MappingT, sup: str) -> tuple[str, _MappingT]: ... class TomlPreserveInlineDictEncoder(TomlEncoder[_MappingT]): From 16f7851167ee5ed88df80f6be2a2a4af84970653 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 18 Jan 2023 14:24:13 -0500 Subject: [PATCH 2/8] See #9567 --- stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi | 3 ++- .../pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi b/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi index 268ee3618eeb..9db499af4e5f 100644 --- a/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi +++ b/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi @@ -4,6 +4,7 @@ from _typeshed import StrOrBytesPath from collections.abc import Generator, Iterable +from types import CodeType from typing import Any from typing_extensions import Literal @@ -50,7 +51,7 @@ class PostGraphAPI: def __name__(self) -> str: ... # Compiled code. See stdlib.builtins.compile @property - def co(self) -> Any: ... + def co(self) -> CodeType: ... @property def analysis(self) -> Analysis: ... @property diff --git a/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi b/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi index ebc7e1c5a8cd..61be3bccfdcc 100644 --- a/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi +++ b/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi @@ -2,7 +2,8 @@ # We reference the vendored package rather than depending on the original untyped module. # Anything not referenced in the PyInstaller stubs doesn't need to be added here. -from typing import Any, Protocol +from types import CodeType +from typing import Protocol class _SupportsGraphident(Protocol): graphident: str @@ -10,7 +11,7 @@ class _SupportsGraphident(Protocol): # code, filename and packagepath are always initialized to None. But they can be given a value later. class Node: # Compiled code. See stdlib.builtins.compile - code: Any | None + code: CodeType | None filename: str | None graphident: str identifier: str From 9c087e5af282dc5a44b124b07ca8dfd638d41804 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Jan 2023 19:25:30 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi b/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi index 9db499af4e5f..a5fddf4bd268 100644 --- a/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi +++ b/stubs/pyinstaller/PyInstaller/depend/imphookapi.pyi @@ -5,7 +5,6 @@ from _typeshed import StrOrBytesPath from collections.abc import Generator, Iterable from types import CodeType -from typing import Any from typing_extensions import Literal from PyInstaller.building.build_main import Analysis From 843b0771a904a4e744177eba9dac91881379e8b2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Feb 2023 12:53:02 -0500 Subject: [PATCH 4/8] Any in toml is correct --- stubs/toml/toml/encoder.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/toml/toml/encoder.pyi b/stubs/toml/toml/encoder.pyi index 3d8adb9b4922..c8be27da7775 100644 --- a/stubs/toml/toml/encoder.pyi +++ b/stubs/toml/toml/encoder.pyi @@ -16,9 +16,9 @@ class TomlEncoder(Generic[_MappingT]): @overload def __init__(self: TomlEncoder[dict[str, Any]], _dict: type[dict[str, Any]] = ..., preserve: bool = ...) -> None: ... def get_empty_table(self) -> _MappingT: ... - def dump_list(self, v: Iterable[object]) -> str: ... - def dump_inline_table(self, section: object) -> str: ... - def dump_value(self, v: object) -> str: ... + def dump_list(self, v: Iterable[Any]) -> str: ... + def dump_inline_table(self, section: dict[str, Any] | Any) -> str: ... + def dump_value(self, v: Any) -> str: ... def dump_sections(self, o: _MappingT, sup: str) -> tuple[str, _MappingT]: ... class TomlPreserveInlineDictEncoder(TomlEncoder[_MappingT]): From d3f6f099b134cc9cda351533261656cbcb2e8963 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Feb 2023 12:58:24 -0500 Subject: [PATCH 5/8] Explain Any Unions in yaml/nodes --- stubs/PyYAML/yaml/nodes.pyi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stubs/PyYAML/yaml/nodes.pyi b/stubs/PyYAML/yaml/nodes.pyi index 2a99dc3ba505..7128049d9bc5 100644 --- a/stubs/PyYAML/yaml/nodes.pyi +++ b/stubs/PyYAML/yaml/nodes.pyi @@ -3,22 +3,25 @@ from typing import Any, ClassVar from yaml.error import Mark +# Any Unions: Avoid forcing the user to check for None when they know what Node was instanciated with +# Using generics may be overkill without support for default Generics +# Permissive Unions could also be useful here. class Node: tag: str - value: Any - start_mark: Mark | Incomplete - end_mark: Mark | Incomplete + value: Incomplete + start_mark: Mark | None | Any + end_mark: Mark | None | Any def __init__(self, tag: str, value, start_mark: Mark | None, end_mark: Mark | None) -> None: ... class ScalarNode(Node): id: ClassVar[str] - style: str | Incomplete + style: str | None | Any def __init__( self, tag: str, value, start_mark: Mark | None = ..., end_mark: Mark | None = ..., style: str | None = ... ) -> None: ... class CollectionNode(Node): - flow_style: bool | Incomplete + flow_style: bool | None | Any def __init__( self, tag: str, value, start_mark: Mark | None = ..., end_mark: Mark | None = ..., flow_style: bool | None = ... ) -> None: ... From 27b9a2bd11b921d3c43cd5fd1da0399872dbc201 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Feb 2023 13:49:57 -0500 Subject: [PATCH 6/8] Fix primer issue --- stubs/PyYAML/yaml/nodes.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/PyYAML/yaml/nodes.pyi b/stubs/PyYAML/yaml/nodes.pyi index 7128049d9bc5..b70907c57a38 100644 --- a/stubs/PyYAML/yaml/nodes.pyi +++ b/stubs/PyYAML/yaml/nodes.pyi @@ -9,19 +9,19 @@ from yaml.error import Mark class Node: tag: str value: Incomplete - start_mark: Mark | None | Any - end_mark: Mark | None | Any + start_mark: Mark | Any + end_mark: Mark | Any def __init__(self, tag: str, value, start_mark: Mark | None, end_mark: Mark | None) -> None: ... class ScalarNode(Node): id: ClassVar[str] - style: str | None | Any + style: str | Any def __init__( self, tag: str, value, start_mark: Mark | None = ..., end_mark: Mark | None = ..., style: str | None = ... ) -> None: ... class CollectionNode(Node): - flow_style: bool | None | Any + flow_style: bool | Any def __init__( self, tag: str, value, start_mark: Mark | None = ..., end_mark: Mark | None = ..., flow_style: bool | None = ... ) -> None: ... From 4c692e6f1aac94dea9b8f211dd5a166aa3ba6c26 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Feb 2023 13:50:33 -0500 Subject: [PATCH 7/8] . --- stubs/PyYAML/yaml/nodes.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stubs/PyYAML/yaml/nodes.pyi b/stubs/PyYAML/yaml/nodes.pyi index b70907c57a38..3308bdcb35d2 100644 --- a/stubs/PyYAML/yaml/nodes.pyi +++ b/stubs/PyYAML/yaml/nodes.pyi @@ -1,4 +1,3 @@ -from _typeshed import Incomplete from typing import Any, ClassVar from yaml.error import Mark @@ -8,7 +7,7 @@ from yaml.error import Mark # Permissive Unions could also be useful here. class Node: tag: str - value: Incomplete + value: Any start_mark: Mark | Any end_mark: Mark | Any def __init__(self, tag: str, value, start_mark: Mark | None, end_mark: Mark | None) -> None: ... From 9f3db1fc4496ff4f5ab43ec21133b5f8d80df72d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 2 Feb 2023 06:38:01 -0800 Subject: [PATCH 8/8] Update stubs/PyYAML/yaml/nodes.pyi --- stubs/PyYAML/yaml/nodes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/PyYAML/yaml/nodes.pyi b/stubs/PyYAML/yaml/nodes.pyi index 3308bdcb35d2..4ee9712607b6 100644 --- a/stubs/PyYAML/yaml/nodes.pyi +++ b/stubs/PyYAML/yaml/nodes.pyi @@ -2,7 +2,7 @@ from typing import Any, ClassVar from yaml.error import Mark -# Any Unions: Avoid forcing the user to check for None when they know what Node was instanciated with +# Any Unions: Avoid forcing the user to check for None when they know what Node was instantiated with # Using generics may be overkill without support for default Generics # Permissive Unions could also be useful here. class Node: