Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stubs/fpdf2/fpdf/drawing.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/fpdf2/fpdf/fpdf.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions stubs/google-cloud-ndb/google/cloud/ndb/client.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]: ...
2 changes: 1 addition & 1 deletion stubs/jsonschema/jsonschema/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/peewee/peewee.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...): ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/pyflakes/pyflakes/checker.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/pygit2/pygit2/utils.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 *'>
Expand Down
4 changes: 2 additions & 2 deletions stubs/pynput/pynput/keyboard/_base.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]]]: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/seaborn/seaborn/_core/plot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion stubs/setuptools/setuptools/wheel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WHEEL_NAME: Any
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: Any
Expand Down
4 changes: 2 additions & 2 deletions stubs/tensorflow/tensorflow/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/tensorflow/tensorflow/autodiff.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...]: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/tensorflow/tensorflow/summary.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions tests/regr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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
Expand Down Expand Up @@ -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:
Expand Down