Use Generator instead of Iterator for 3rd-party context managers (#12481)

This commit is contained in:
Max Muoto
2024-08-12 07:26:18 -05:00
committed by GitHub
parent 0b6f15c2ff
commit 37807d753a
14 changed files with 22 additions and 22 deletions

View File

@@ -1,7 +1,7 @@
import decimal
from _typeshed import Incomplete
from collections import OrderedDict
from collections.abc import Callable, Generator, Iterator, Sequence
from collections.abc import Callable, Generator, Sequence
from contextlib import contextmanager
from re import Pattern
from typing import Any, ClassVar, Literal, NamedTuple, TypeVar, overload
@@ -354,7 +354,7 @@ class PaintedPath:
@clipping_path.setter
def clipping_path(self, new_clipath) -> None: ...
@contextmanager
def transform_group(self, transform) -> Iterator[Self]: ...
def transform_group(self, transform) -> Generator[Self]: ...
def add_path_element(self, item, _copy: bool = True) -> None: ...
def remove_last_path_element(self) -> None: ...
def rectangle(self, x, y, w, h, rx: int = 0, ry: int = 0) -> Self: ...

View File

@@ -426,7 +426,7 @@ class FPDF(GraphicsStateMixin):
def skew(
self, ax: float = 0, ay: float = 0, x: float | None = None, y: float | None = None
) -> _GeneratorContextManager[None]: ...
def mirror(self, origin, angle) -> Generator[None, None, None]: ...
def mirror(self, origin, angle) -> Generator[None]: ...
def local_context(
self,
font_family: Incomplete | None = None,

View File

@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator
from contextlib import contextmanager
from typing import ClassVar
@@ -32,4 +32,4 @@ class Client:
global_cache_policy: Callable[[key.Key], bool] | None = ...,
global_cache_timeout_policy: Callable[[key.Key], int] | None = ...,
legacy_data: bool = ...,
) -> Iterator[context_module.Context]: ...
) -> Generator[context_module.Context]: ...

View File

@@ -107,7 +107,7 @@ class RefResolver:
@property
def base_uri(self): ...
@contextmanager
def in_scope(self, scope) -> Generator[None, None, None]: ...
def in_scope(self, scope) -> Generator[None]: ...
@contextmanager
def resolving(self, ref) -> Generator[Incomplete, None, None]: ...
def resolve(self, ref): ...

View File

@@ -98,7 +98,7 @@ class Context:
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
def push_alias(self) -> Generator[None, None, None]: ...
def push_alias(self) -> Generator[None]: ...
def sql(self, obj): ...
def literal(self, keyword): ...
def value(self, value, converter: Incomplete | None = ..., add_param: bool = ...): ...

View File

@@ -1,6 +1,6 @@
import ast
import sys
from collections.abc import Callable, Iterable, Iterator
from collections.abc import Callable, Generator, Iterable, Iterator
from contextlib import contextmanager
from re import Pattern
from typing import Any, ClassVar, Literal, TypeVar, overload
@@ -203,7 +203,7 @@ class Checker:
@property
def scope(self) -> Scope: ...
@contextmanager
def in_scope(self, cls: Callable[[], Scope]) -> Iterator[None]: ...
def in_scope(self, cls: Callable[[], Scope]) -> Generator[None]: ...
def checkDeadScopes(self) -> None: ...
def report(self, messageClass: Callable[_P, Message], *args: _P.args, **kwargs: _P.kwargs) -> None: ...
def getParent(self, node: ast.AST) -> ast.AST: ...

View File

@@ -1,7 +1,7 @@
import contextlib
import types
from _typeshed import StrOrBytesPath, StrPath
from collections.abc import Iterator
from collections.abc import Generator
from typing import Generic, TypeVar
from typing_extensions import TypeAlias
@@ -12,7 +12,7 @@ def to_bytes(s: _CDataBase | StrOrBytesPath | None, encoding: str = "utf-8", err
def to_str(s: StrOrBytesPath) -> str: ...
def ptr_to_bytes(ptr_cdata: _CDataBase) -> bytes: ...
@contextlib.contextmanager
def new_git_strarray() -> Iterator[_GitStrArray]: ...
def new_git_strarray() -> Generator[_GitStrArray]: ...
def strarray_to_strings(arr: _GitStrArray) -> list[str]: ...
# Actual type: _cffi_backend.__CDataOwn <cdata 'struct git_strarray *'>

View File

@@ -1,7 +1,7 @@
import contextlib
import enum
import sys
from collections.abc import Callable, Iterable, Iterator
from collections.abc import Callable, Generator, Iterable, Iterator
from typing import Any, ClassVar
from typing_extensions import Self
@@ -108,7 +108,7 @@ class Controller:
def tap(self, key: str | Key | KeyCode) -> None: ...
def touch(self, key: str | Key | KeyCode, is_press: bool) -> None: ...
@contextlib.contextmanager
def pressed(self, *args: str | Key | KeyCode) -> Iterator[None]: ...
def pressed(self, *args: str | Key | KeyCode) -> Generator[None]: ...
def type(self, string: str) -> None: ...
@property
def modifiers(self) -> contextlib.AbstractContextManager[Iterator[set[Key]]]: ...

View File

@@ -46,7 +46,7 @@ class PairSpec(TypedDict, total=False):
wrap: int | None
@contextmanager
def theme_context(params: dict[str, Any]) -> Generator[None, None, None]: ...
def theme_context(params: dict[str, Any]) -> Generator[None]: ...
def build_plot_signature(cls: _ClsT) -> _ClsT: ... # -> _ClsT & "__signature__ protocol"
class ThemeConfig(mpl.RcParams):

View File

@@ -5,7 +5,7 @@ WHEEL_NAME: Incomplete
NAMESPACE_PACKAGE_INIT: str
def unpack(src_dir, dst_dir) -> None: ...
def disable_info_traces() -> Generator[None, None, None]: ...
def disable_info_traces() -> Generator[None]: ...
class Wheel:
filename: Incomplete

View File

@@ -2,7 +2,7 @@ import abc
from _typeshed import Incomplete, Unused
from abc import ABC, ABCMeta, abstractmethod
from builtins import bool as _bool
from collections.abc import Callable, Iterable, Iterator, Sequence
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from contextlib import contextmanager
from enum import Enum
from types import TracebackType
@@ -228,7 +228,7 @@ class Graph:
def add_to_collection(self, name: str, value: object) -> None: ...
def add_to_collections(self, names: Iterable[str] | str, value: object) -> None: ...
@contextmanager
def as_default(self) -> Iterator[Self]: ...
def as_default(self) -> Generator[Self]: ...
def finalize(self) -> None: ...
def get_tensor_by_name(self, name: str) -> Tensor: ...
def get_operation_by_name(self, name: str) -> Operation: ...

View File

@@ -56,7 +56,7 @@ class GradientTape:
unconnected_gradients: UnconnectedGradients = ...,
) -> ContainerGradients: ...
@contextmanager
def stop_recording(self) -> Generator[None, None, None]: ...
def stop_recording(self) -> Generator[None]: ...
def reset(self) -> None: ...
def watch(self, tensor: ContainerTensorsLike) -> None: ...
def watched_variables(self) -> tuple[Variable, ...]: ...

View File

@@ -1,6 +1,6 @@
import abc
from _typeshed import Incomplete
from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator
from contextlib import AbstractContextManager, contextmanager
from typing import Literal
from typing_extensions import Self
@@ -49,7 +49,7 @@ def image(
description: str | None = None,
) -> bool: ...
@contextmanager
def record_if(condition: bool | tf.Tensor | Callable[[], bool]) -> Iterator[None]: ...
def record_if(condition: bool | tf.Tensor | Callable[[], bool]) -> Generator[None]: ...
def scalar(name: str, data: float | tf.Tensor, step: int | tf.Tensor | None = None, description: str | None = None) -> bool: ...
def should_record_summaries() -> bool: ...
def text(name: str, data: str | tf.Tensor, step: int | tf.Tensor | None = None, description: str | None = None) -> bool: ...

View File

@@ -13,7 +13,7 @@ import subprocess
import sys
import tempfile
import threading
from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator
from contextlib import ExitStack, contextmanager, suppress
from dataclasses import dataclass
from enum import IntEnum
@@ -316,7 +316,7 @@ def concurrently_run_testcases(
@contextmanager
def cleanup_threads(
event: threading.Event, printer_thread: threading.Thread, executor: concurrent.futures.ThreadPoolExecutor
) -> Iterator[None]:
) -> Generator[None]:
try:
yield
except: