timeout: Remove unnecessary varargs support.

Mypy can check it this way.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-15 15:56:23 -08:00
committed by Tim Abbott
parent 77b7914cd7
commit b728727d9d
2 changed files with 5 additions and 5 deletions

View File

@@ -420,7 +420,7 @@ def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]:
# preview, rather than having the message be rejected
# entirely. This timeout needs to be less than our overall
# formatting timeout.
tweet = timeout(3, api.GetStatus, tweet_id)
tweet = timeout(3, lambda: api.GetStatus(tweet_id))
res = tweet.AsDict()
except TimeoutExpired:
# We'd like to try again later and not cache the bad result,
@@ -2541,7 +2541,7 @@ def do_convert(
# extremely inefficient in corner cases) as well as user
# errors (e.g. a realm filter that makes some syntax
# infinite-loop).
rendered_content = timeout(5, _md_engine.convert, content)
rendered_content = timeout(5, lambda: _md_engine.convert(content))
# Throw an exception if the content is huge; this protects the
# rest of the codebase from any bugs where we end up rendering

View File

@@ -3,7 +3,7 @@ import sys
import threading
import time
from types import TracebackType
from typing import Any, Callable, Optional, Tuple, Type, TypeVar
from typing import Callable, Optional, Tuple, Type, TypeVar
# Based on https://code.activestate.com/recipes/483752/
@@ -18,7 +18,7 @@ class TimeoutExpired(Exception):
ResultT = TypeVar("ResultT")
def timeout(timeout: float, func: Callable[..., ResultT], *args: Any, **kwargs: Any) -> ResultT:
def timeout(timeout: float, func: Callable[[], ResultT]) -> ResultT:
"""Call the function in a separate thread.
Return its return value, or raise an exception,
within approximately 'timeout' seconds.
@@ -50,7 +50,7 @@ def timeout(timeout: float, func: Callable[..., ResultT], *args: Any, **kwargs:
def run(self) -> None:
try:
self.result = func(*args, **kwargs)
self.result = func()
except BaseException:
self.exc_info = sys.exc_info()