diff --git a/.flake8 b/.flake8 index ee79a2a35..f463a8c05 100644 --- a/.flake8 +++ b/.flake8 @@ -18,9 +18,6 @@ # F405 defined from star imports # Rules that we'd like to enable in the future: -# Y027 Disallow importing typing.ContextManager, typing.OrderedDict & -# typing_extensions.OrderedDict (cannot be globally enabled while typeshed -# still contains stubs supporting Python 2). # Y034 Detect common errors where certain methods are annotated as having a fixed # return type, despite returning self at runtime (temporarily disabled for # typing.pyi, enabled elsewhere). @@ -36,7 +33,6 @@ per-file-ignores = # Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself. # https://github.com/PyCQA/flake8/issues/1079 # F811 redefinition of unused '...' - stubs/*.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y027, Y037 stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y034, Y037 exclude = .venv*,.git,*_pb2.pyi,stdlib/@python2/* diff --git a/stubs/Deprecated/deprecated/classic.pyi b/stubs/Deprecated/deprecated/classic.pyi index a93337a89..95704e886 100644 --- a/stubs/Deprecated/deprecated/classic.pyi +++ b/stubs/Deprecated/deprecated/classic.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, TypeVar, overload +from collections.abc import Callable +from typing import Any, TypeVar, overload from typing_extensions import Literal, TypeAlias _F = TypeVar("_F", bound=Callable[..., Any]) diff --git a/stubs/Deprecated/deprecated/sphinx.pyi b/stubs/Deprecated/deprecated/sphinx.pyi index 7e6199645..e840e5225 100644 --- a/stubs/Deprecated/deprecated/sphinx.pyi +++ b/stubs/Deprecated/deprecated/sphinx.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, TypeVar +from collections.abc import Callable +from typing import Any, TypeVar from typing_extensions import Literal from .classic import ClassicAdapter, _Actions diff --git a/stubs/Flask-Cors/flask_cors/decorator.pyi b/stubs/Flask-Cors/flask_cors/decorator.pyi index fa70decc4..759a5dea8 100644 --- a/stubs/Flask-Cors/flask_cors/decorator.pyi +++ b/stubs/Flask-Cors/flask_cors/decorator.pyi @@ -1,7 +1,7 @@ -from collections.abc import Callable +from collections.abc import Callable, Iterable from datetime import timedelta from logging import Logger -from typing import Any, Iterable, Pattern +from typing import Any, Pattern from typing_extensions import ParamSpec _P = ParamSpec("_P") diff --git a/stubs/SQLAlchemy/sqlalchemy/orm/query.pyi b/stubs/SQLAlchemy/sqlalchemy/orm/query.pyi index cc7a9f754..46e20de51 100644 --- a/stubs/SQLAlchemy/sqlalchemy/orm/query.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/orm/query.pyi @@ -1,5 +1,6 @@ from _typeshed import Self -from typing import Any, Generic, Iterator, TypeVar +from collections.abc import Iterator +from typing import Any, Generic, TypeVar from ..sql.annotation import SupportsCloneAnnotations from ..sql.base import Executable diff --git a/stubs/atomicwrites/atomicwrites/__init__.pyi b/stubs/atomicwrites/atomicwrites/__init__.pyi index 8f5431d48..f5ea4ac29 100644 --- a/stubs/atomicwrites/atomicwrites/__init__.pyi +++ b/stubs/atomicwrites/atomicwrites/__init__.pyi @@ -1,17 +1,20 @@ from _typeshed import StrOrBytesPath from collections.abc import Callable -from typing import IO, Any, AnyStr, ContextManager +from contextlib import AbstractContextManager +from typing import IO, Any, AnyStr def replace_atomic(src: AnyStr, dst: AnyStr) -> None: ... def move_atomic(src: AnyStr, dst: AnyStr) -> None: ... class AtomicWriter: def __init__(self, path: StrOrBytesPath, mode: str = ..., overwrite: bool = ...) -> None: ... - def open(self) -> ContextManager[IO[Any]]: ... - def _open(self, get_fileobject: Callable[..., IO[AnyStr]]) -> ContextManager[IO[AnyStr]]: ... + def open(self) -> AbstractContextManager[IO[Any]]: ... + def _open(self, get_fileobject: Callable[..., IO[AnyStr]]) -> AbstractContextManager[IO[AnyStr]]: ... def get_fileobject(self, dir: StrOrBytesPath | None = ..., **kwargs: Any) -> IO[Any]: ... def sync(self, f: IO[Any]) -> None: ... def commit(self, f: IO[Any]) -> None: ... def rollback(self, f: IO[Any]) -> None: ... -def atomic_write(path: StrOrBytesPath, writer_cls: type[AtomicWriter] = ..., **cls_kwargs: object) -> ContextManager[IO[Any]]: ... +def atomic_write( + path: StrOrBytesPath, writer_cls: type[AtomicWriter] = ..., **cls_kwargs: object +) -> AbstractContextManager[IO[Any]]: ... diff --git a/stubs/characteristic/characteristic/__init__.pyi b/stubs/characteristic/characteristic/__init__.pyi index d60ff1a35..905fdaa2c 100644 --- a/stubs/characteristic/characteristic/__init__.pyi +++ b/stubs/characteristic/characteristic/__init__.pyi @@ -1,4 +1,5 @@ -from typing import Any, AnyStr, Callable, Sequence, TypeVar +from collections.abc import Callable, Sequence +from typing import Any, AnyStr, TypeVar def with_repr(attrs: Sequence[AnyStr | Attribute]) -> Callable[..., Any]: ... def with_cmp(attrs: Sequence[AnyStr | Attribute]) -> Callable[..., Any]: ... diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi index 3c0569853..6e3359e7e 100644 --- a/stubs/colorama/colorama/ansitowin32.pyi +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -1,7 +1,8 @@ import sys from _typeshed import SupportsWrite +from collections.abc import Callable, Sequence from types import TracebackType -from typing import Any, Callable, Pattern, Sequence, TextIO +from typing import Any, Pattern, TextIO from typing_extensions import TypeAlias if sys.platform == "win32": diff --git a/stubs/colorama/colorama/initialise.pyi b/stubs/colorama/colorama/initialise.pyi index f76f826e0..f0c12f2de 100644 --- a/stubs/colorama/colorama/initialise.pyi +++ b/stubs/colorama/colorama/initialise.pyi @@ -1,4 +1,5 @@ -from typing import Any, ContextManager, TextIO +from contextlib import AbstractContextManager +from typing import Any, TextIO from .ansitowin32 import StreamWrapper @@ -11,7 +12,7 @@ atexit_done: bool def reset_all() -> None: ... def init(autoreset: bool = ..., convert: bool | None = ..., strip: bool | None = ..., wrap: bool = ...) -> None: ... def deinit() -> None: ... -def colorama_text(*args: Any, **kwargs: Any) -> ContextManager[None]: ... +def colorama_text(*args: Any, **kwargs: Any) -> AbstractContextManager[None]: ... def reinit() -> None: ... def wrap_stream( stream: TextIO, convert: bool | None, strip: bool | None, autoreset: bool, wrap: bool diff --git a/stubs/colorama/colorama/win32.pyi b/stubs/colorama/colorama/win32.pyi index 0a6f4ca23..713aaf273 100644 --- a/stubs/colorama/colorama/win32.pyi +++ b/stubs/colorama/colorama/win32.pyi @@ -1,5 +1,5 @@ import sys -from typing import Callable +from collections.abc import Callable from typing_extensions import Literal STDOUT: Literal[-11] diff --git a/stubs/docopt/docopt.pyi b/stubs/docopt/docopt.pyi index c272c4de0..9984de2ee 100644 --- a/stubs/docopt/docopt.pyi +++ b/stubs/docopt/docopt.pyi @@ -1,4 +1,5 @@ -from typing import Any, Iterable +from collections.abc import Iterable +from typing import Any from typing_extensions import TypeAlias __version__: str diff --git a/stubs/first/first.pyi b/stubs/first/first.pyi index 2306d521b..d2e894151 100644 --- a/stubs/first/first.pyi +++ b/stubs/first/first.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, Iterable, TypeVar, overload +from collections.abc import Callable, Iterable +from typing import Any, TypeVar, overload _T = TypeVar("_T") _S = TypeVar("_S") diff --git a/stubs/mypy-extensions/mypy_extensions.pyi b/stubs/mypy-extensions/mypy_extensions.pyi index dd4a2ab02..412c3cb15 100644 --- a/stubs/mypy-extensions/mypy_extensions.pyi +++ b/stubs/mypy-extensions/mypy_extensions.pyi @@ -1,6 +1,7 @@ import abc from _typeshed import Self -from typing import Any, Callable, Generic, ItemsView, KeysView, Mapping, TypeVar, ValuesView +from collections.abc import Callable, ItemsView, KeysView, Mapping, ValuesView +from typing import Any, Generic, TypeVar _T = TypeVar("_T") _U = TypeVar("_U") diff --git a/stubs/parsimonious/parsimonious/expressions.pyi b/stubs/parsimonious/parsimonious/expressions.pyi index c89623b09..efb8db7b0 100644 --- a/stubs/parsimonious/parsimonious/expressions.pyi +++ b/stubs/parsimonious/parsimonious/expressions.pyi @@ -1,4 +1,4 @@ -import typing +import collections.abc from collections.abc import Callable, Mapping from typing import Any, Pattern, Union from typing_extensions import TypeAlias @@ -50,7 +50,7 @@ class Regex(Expression): ) -> None: ... class Compound(Expression): - members: typing.Sequence[Expression] + members: collections.abc.Sequence[Expression] def __init__(self, *members: Expression, **kwargs: Any) -> None: ... class Sequence(Compound): ... diff --git a/stubs/parsimonious/parsimonious/grammar.pyi b/stubs/parsimonious/parsimonious/grammar.pyi index a0acc9e47..a302df492 100644 --- a/stubs/parsimonious/parsimonious/grammar.pyi +++ b/stubs/parsimonious/parsimonious/grammar.pyi @@ -1,4 +1,4 @@ -import typing +import collections.abc from collections import OrderedDict from collections.abc import Callable, Mapping from typing import Any, NoReturn @@ -23,32 +23,34 @@ class LazyReference(str): class RuleVisitor(NodeVisitor): quantifier_classes: dict[str, type[Expression]] - visit_expression: Callable[[RuleVisitor, Node, typing.Sequence[Any]], Any] - visit_term: Callable[[RuleVisitor, Node, typing.Sequence[Any]], Any] - visit_atom: Callable[[RuleVisitor, Node, typing.Sequence[Any]], Any] + visit_expression: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any] + visit_term: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any] + visit_atom: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any] custom_rules: dict[str, Expression] def __init__(self, custom_rules: Mapping[str, Expression] | None = ...) -> None: ... def visit_rules( - self, node: Node, rules_list: typing.Sequence[Any] + self, node: Node, rules_list: collections.abc.Sequence[Any] ) -> tuple[OrderedDict[str, Expression], Expression | None]: ... - def visit_rule(self, node: Node, rule: typing.Sequence[Any]) -> Expression: ... - def visit_label(self, node: Node, label: typing.Sequence[Any]) -> str: ... - def visit_ored(self, node: Node, ored: typing.Sequence[Any]) -> OneOf: ... - def visit_or_term(self, node: Node, or_term: typing.Sequence[Any]) -> Expression: ... - def visit_sequence(self, node: Node, sequence: typing.Sequence[Any]) -> Sequence: ... - def visit_not_term(self, node: Node, not_term: typing.Sequence[Any]) -> Not: ... - def visit_lookahead_term(self, node: Node, lookahead_term: typing.Sequence[Any]) -> Lookahead: ... - def visit_quantified(self, node: Node, quantified: typing.Sequence[Any]) -> Expression: ... - def visit_quantifier(self, node: Node, quantifier: typing.Sequence[Any]) -> Node: ... - def visit_reference(self, node: Node, reference: typing.Sequence[Any]) -> LazyReference: ... - def visit_literal(self, node: Node, literal: typing.Sequence[Any]) -> Literal: ... - def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: typing.Sequence[Any]) -> Literal: ... - def visit_regex(self, node: Node, regex: typing.Sequence[Any]) -> Regex: ... - def visit_parenthesized(self, node: Node, parenthesized: typing.Sequence[Any]) -> Expression: ... - def generic_visit(self, node: Node, visited_children: typing.Sequence[Any]) -> typing.Sequence[Any] | Node: ... # type: ignore[override] + def visit_rule(self, node: Node, rule: collections.abc.Sequence[Any]) -> Expression: ... + def visit_label(self, node: Node, label: collections.abc.Sequence[Any]) -> str: ... + def visit_ored(self, node: Node, ored: collections.abc.Sequence[Any]) -> OneOf: ... + def visit_or_term(self, node: Node, or_term: collections.abc.Sequence[Any]) -> Expression: ... + def visit_sequence(self, node: Node, sequence: collections.abc.Sequence[Any]) -> Sequence: ... + def visit_not_term(self, node: Node, not_term: collections.abc.Sequence[Any]) -> Not: ... + def visit_lookahead_term(self, node: Node, lookahead_term: collections.abc.Sequence[Any]) -> Lookahead: ... + def visit_quantified(self, node: Node, quantified: collections.abc.Sequence[Any]) -> Expression: ... + def visit_quantifier(self, node: Node, quantifier: collections.abc.Sequence[Any]) -> Node: ... + def visit_reference(self, node: Node, reference: collections.abc.Sequence[Any]) -> LazyReference: ... + def visit_literal(self, node: Node, literal: collections.abc.Sequence[Any]) -> Literal: ... + def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: collections.abc.Sequence[Any]) -> Literal: ... + def visit_regex(self, node: Node, regex: collections.abc.Sequence[Any]) -> Regex: ... + def visit_parenthesized(self, node: Node, parenthesized: collections.abc.Sequence[Any]) -> Expression: ... + def generic_visit(self, node: Node, visited_children: collections.abc.Sequence[Any]) -> collections.abc.Sequence[Any] | Node: ... # type: ignore[override] class TokenRuleVisitor(RuleVisitor): - def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: typing.Sequence[Any]) -> TokenMatcher: ... - def visit_regex(self, node: Node, regex: typing.Sequence[Any]) -> NoReturn: ... + def visit_spaceless_literal( + self, spaceless_literal: Node, visited_children: collections.abc.Sequence[Any] + ) -> TokenMatcher: ... + def visit_regex(self, node: Node, regex: collections.abc.Sequence[Any]) -> NoReturn: ... rule_grammar: Grammar diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 127ed73a7..a08d6cbf4 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,4 +1,4 @@ -from typing import Callable, Mapping, Sequence +from collections.abc import Callable, Mapping, Sequence from typing_extensions import Final, TypeAlias paFloat32: Final[int] diff --git a/stubs/python-dateutil/dateutil/rrule.pyi b/stubs/python-dateutil/dateutil/rrule.pyi index ef4e5edde..c4793044d 100644 --- a/stubs/python-dateutil/dateutil/rrule.pyi +++ b/stubs/python-dateutil/dateutil/rrule.pyi @@ -1,5 +1,6 @@ import datetime -from typing import Any, Iterable +from collections.abc import Iterable +from typing import Any from typing_extensions import TypeAlias from ._common import weekday as weekdaybase diff --git a/stubs/pytz/pytz/__init__.pyi b/stubs/pytz/pytz/__init__.pyi index 4838e7614..6a2f148a6 100644 --- a/stubs/pytz/pytz/__init__.pyi +++ b/stubs/pytz/pytz/__init__.pyi @@ -1,5 +1,6 @@ import datetime -from typing import ClassVar, Mapping +from collections.abc import Mapping +from typing import ClassVar from .exceptions import ( AmbiguousTimeError as AmbiguousTimeError, diff --git a/stubs/redis/redis/asyncio/client.pyi b/stubs/redis/redis/asyncio/client.pyi index 263903a8d..87a13d14a 100644 --- a/stubs/redis/redis/asyncio/client.pyi +++ b/stubs/redis/redis/asyncio/client.pyi @@ -1,6 +1,6 @@ from _typeshed import Self -from collections.abc import AsyncIterator, Callable, Iterable, Mapping, MutableMapping -from typing import Any, Awaitable, Generic, NoReturn, Protocol +from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Mapping, MutableMapping +from typing import Any, Generic, NoReturn, Protocol from typing_extensions import TypeAlias, TypedDict from redis.asyncio.connection import Connection, ConnectionPool diff --git a/stubs/redis/redis/asyncio/lock.pyi b/stubs/redis/redis/asyncio/lock.pyi index 579cd08df..e2285460b 100644 --- a/stubs/redis/redis/asyncio/lock.pyi +++ b/stubs/redis/redis/asyncio/lock.pyi @@ -1,4 +1,5 @@ -from typing import Any, Awaitable +from collections.abc import Awaitable +from typing import Any from redis.asyncio import Redis diff --git a/stubs/redis/redis/asyncio/retry.pyi b/stubs/redis/redis/asyncio/retry.pyi index 48135f504..4d847684c 100644 --- a/stubs/redis/redis/asyncio/retry.pyi +++ b/stubs/redis/redis/asyncio/retry.pyi @@ -1,5 +1,5 @@ -from collections.abc import Callable -from typing import Any, Awaitable, TypeVar +from collections.abc import Awaitable, Callable +from typing import Any, TypeVar from redis.backoff import AbstractBackoff from redis.exceptions import RedisError diff --git a/stubs/redis/redis/commands/core.pyi b/stubs/redis/redis/commands/core.pyi index a3af49328..7a914249a 100644 --- a/stubs/redis/redis/commands/core.pyi +++ b/stubs/redis/redis/commands/core.pyi @@ -1,7 +1,7 @@ import builtins -from collections.abc import AsyncIterator, Callable, Iterable, Iterator, Mapping, Sequence +from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Iterator, Mapping, Sequence from datetime import datetime, timedelta -from typing import Any, Awaitable, Generic, TypeVar, overload +from typing import Any, Generic, TypeVar, overload from typing_extensions import Literal from ..asyncio.client import Redis as AsyncRedis diff --git a/stubs/retry/retry/api.pyi b/stubs/retry/retry/api.pyi index c74e32ee5..32f16dd5e 100644 --- a/stubs/retry/retry/api.pyi +++ b/stubs/retry/retry/api.pyi @@ -1,6 +1,7 @@ from _typeshed import IdentityFunction +from collections.abc import Callable, Sequence from logging import Logger -from typing import Any, Callable, Sequence, TypeVar +from typing import Any, TypeVar _R = TypeVar("_R") diff --git a/stubs/singledispatch/singledispatch.pyi b/stubs/singledispatch/singledispatch.pyi index 28c735b8f..59d201deb 100644 --- a/stubs/singledispatch/singledispatch.pyi +++ b/stubs/singledispatch/singledispatch.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, Generic, Mapping, TypeVar, overload +from collections.abc import Callable, Mapping +from typing import Any, Generic, TypeVar, overload _T = TypeVar("_T") diff --git a/stubs/tabulate/tabulate.pyi b/stubs/tabulate/tabulate.pyi index d1d4669f0..30c8329bf 100644 --- a/stubs/tabulate/tabulate.pyi +++ b/stubs/tabulate/tabulate.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, Container, Iterable, Mapping, NamedTuple, Sequence +from collections.abc import Callable, Container, Iterable, Mapping, Sequence +from typing import Any, NamedTuple from typing_extensions import TypeAlias LATEX_ESCAPE_RULES: dict[str, str] diff --git a/stubs/toml/toml/encoder.pyi b/stubs/toml/toml/encoder.pyi index 0fdd7145b..992b18e2b 100644 --- a/stubs/toml/toml/encoder.pyi +++ b/stubs/toml/toml/encoder.pyi @@ -1,5 +1,6 @@ from _typeshed import SupportsWrite -from typing import Any, Callable, Generic, Iterable, Mapping, MutableMapping, TypeVar, overload +from collections.abc import Callable, Iterable, Mapping, MutableMapping +from typing import Any, Generic, TypeVar, overload _MappingT = TypeVar("_MappingT", bound=Mapping[str, Any])