From d5df528e8c9e430db15a87cfe0b645d1bf22e51b Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Mon, 15 Jul 2024 05:34:43 +0100 Subject: [PATCH] Shrink the mypy whitelist for ``sphinx.util.display`` (#12570) Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com> --- pyproject.toml | 1 - sphinx/util/display.py | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 87fa5e7a47a..3d8cce18c20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -264,7 +264,6 @@ module = [ "sphinx.registry", "sphinx.search", "sphinx.util", - "sphinx.util.display", "sphinx.util.docfields", "sphinx.util.docutils", "sphinx.util.i18n", diff --git a/sphinx/util/display.py b/sphinx/util/display.py index b39a3672944..f3ff8a5a255 100644 --- a/sphinx/util/display.py +++ b/sphinx/util/display.py @@ -1,7 +1,6 @@ from __future__ import annotations import functools -from typing import Any, Callable, TypeVar from sphinx.locale import __ from sphinx.util import logging @@ -10,6 +9,13 @@ if False: from collections.abc import Iterable, Iterator from types import TracebackType + from typing import Any, Callable, TypeVar + + from typing_extensions import ParamSpec + + T = TypeVar('T') + P = ParamSpec('P') + R = TypeVar('R') logger = logging.getLogger(__name__) @@ -22,9 +28,6 @@ def display_chunk(chunk: Any) -> str: return str(chunk) -T = TypeVar('T') - - def status_iterator( iterable: Iterable[T], summary: str, @@ -88,9 +91,9 @@ def __exit__( return False - def __call__(self, f: Callable) -> Callable: + def __call__(self, f: Callable[P, R]) -> Callable[P, R]: @functools.wraps(f) - def wrapper(*args: Any, **kwargs: Any) -> Any: + def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: # type: ignore[return] with self: return f(*args, **kwargs)