Import generics from standard modules in all third-party stubs (#7791)

This commit is contained in:
Alex Waygood
2022-05-07 09:35:50 +01:00
committed by GitHub
parent 6c6c669ada
commit 5c6178a821
26 changed files with 76 additions and 59 deletions

View File

@@ -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/*

View File

@@ -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])

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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]]: ...

View File

@@ -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]: ...

View File

@@ -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":

View File

@@ -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

View File

@@ -1,5 +1,5 @@
import sys
from typing import Callable
from collections.abc import Callable
from typing_extensions import Literal
STDOUT: Literal[-11]

View File

@@ -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

View File

@@ -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")

View File

@@ -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")

View File

@@ -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): ...

View File

@@ -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

View File

@@ -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]

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -1,4 +1,5 @@
from typing import Any, Awaitable
from collections.abc import Awaitable
from typing import Any
from redis.asyncio import Redis

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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")

View File

@@ -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]

View File

@@ -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])