From 506e89643c6bf3b180d52e93ccd519c317b8e235 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Mon, 7 Dec 2020 15:10:48 +0700 Subject: [PATCH 1/2] add type hint for decorated function Currently some language servers cannot parse the type of wrapped functions. _TFunc is bounded to the function. --- allure-python-commons/src/_allure.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/allure-python-commons/src/_allure.py b/allure-python-commons/src/_allure.py index 5cc92966..21bce904 100644 --- a/allure-python-commons/src/_allure.py +++ b/allure-python-commons/src/_allure.py @@ -1,10 +1,12 @@ from functools import wraps +from typing import Any, Callable, TypeVar from allure_commons._core import plugin_manager from allure_commons.types import LabelType, LinkType from allure_commons.utils import uuid4 from allure_commons.utils import func_parameters, represent +_TFunc = TypeVar("_TFunc", bound=Callable[..., Any]) def safely(result): if result: @@ -159,7 +161,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): plugin_manager.hook.stop_step(uuid=self.uuid, title=self.title, exc_type=exc_type, exc_val=exc_val, exc_tb=exc_tb) - def __call__(self, func): + def __call__(self, func: _TFunc) -> _TFunc: @wraps(func) def impl(*a, **kw): __tracebackhide__ = True From d1075ea3d9ef6c53aaf77b5126e387c112a9fdda Mon Sep 17 00:00:00 2001 From: jackblk Date: Mon, 7 Dec 2020 16:54:09 +0700 Subject: [PATCH 2/2] fix static check add one more space to pass static check --- allure-python-commons/src/_allure.py | 1 + 1 file changed, 1 insertion(+) diff --git a/allure-python-commons/src/_allure.py b/allure-python-commons/src/_allure.py index 21bce904..565ac955 100644 --- a/allure-python-commons/src/_allure.py +++ b/allure-python-commons/src/_allure.py @@ -8,6 +8,7 @@ _TFunc = TypeVar("_TFunc", bound=Callable[..., Any]) + def safely(result): if result: return result[0]