Skip to content

Commit

Permalink
Import generics from standard modules in all third-party stubs (#7791)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored May 7, 2022
1 parent 6c6c669 commit 5c6178a
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 59 deletions.
4 changes: 0 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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/*
3 changes: 2 additions & 1 deletion stubs/Deprecated/deprecated/classic.pyi
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
3 changes: 2 additions & 1 deletion stubs/Deprecated/deprecated/sphinx.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stubs/Flask-Cors/flask_cors/decorator.pyi
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
3 changes: 2 additions & 1 deletion stubs/SQLAlchemy/sqlalchemy/orm/query.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions stubs/atomicwrites/atomicwrites/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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]]: ...
3 changes: 2 additions & 1 deletion stubs/characteristic/characteristic/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/colorama/colorama/ansitowin32.pyi
Original file line number Diff line number Diff line change
@@ -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":
Expand Down
5 changes: 3 additions & 2 deletions stubs/colorama/colorama/initialise.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, ContextManager, TextIO
from contextlib import AbstractContextManager
from typing import Any, TextIO

from .ansitowin32 import StreamWrapper

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stubs/colorama/colorama/win32.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import Callable
from collections.abc import Callable
from typing_extensions import Literal

STDOUT: Literal[-11]
Expand Down
3 changes: 2 additions & 1 deletion stubs/docopt/docopt.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion stubs/first/first.pyi
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
3 changes: 2 additions & 1 deletion stubs/mypy-extensions/mypy_extensions.pyi
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
4 changes: 2 additions & 2 deletions stubs/parsimonious/parsimonious/expressions.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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): ...
Expand Down
46 changes: 24 additions & 22 deletions stubs/parsimonious/parsimonious/grammar.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
import collections.abc
from collections import OrderedDict
from collections.abc import Callable, Mapping
from typing import Any, NoReturn
Expand All @@ -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
2 changes: 1 addition & 1 deletion stubs/pyaudio/pyaudio.pyi
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 2 additions & 1 deletion stubs/python-dateutil/dateutil/rrule.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion stubs/pytz/pytz/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions stubs/redis/redis/asyncio/client.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion stubs/redis/redis/asyncio/lock.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Awaitable
from collections.abc import Awaitable
from typing import Any

from redis.asyncio import Redis

Expand Down
4 changes: 2 additions & 2 deletions stubs/redis/redis/asyncio/retry.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stubs/redis/redis/commands/core.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion stubs/retry/retry/api.pyi
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
3 changes: 2 additions & 1 deletion stubs/singledispatch/singledispatch.pyi
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
3 changes: 2 additions & 1 deletion stubs/tabulate/tabulate.pyi
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 2 additions & 1 deletion stubs/toml/toml/encoder.pyi
Original file line number Diff line number Diff line change
@@ -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])

Expand Down

0 comments on commit 5c6178a

Please sign in to comment.