From 8b55bb655643772a25d57eafc1bcabb16e940970 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Tue, 8 Dec 2020 15:36:11 +0100 Subject: [PATCH] src,qa: Upgrade to mypy 0.790 dashboard/tools: Make sure {begin,end}_time are set. Signed-off-by: Sebastian Wagner --- qa/tox.ini | 2 +- src/cephadm/tox.ini | 2 +- src/pybind/mgr/dashboard/tools.py | 25 ++++++++++++++++++------- src/pybind/mgr/tox.ini | 2 +- src/python-common/requirements.txt | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/qa/tox.ini b/qa/tox.ini index e1583649f8ccb..eac9e53701d3f 100644 --- a/qa/tox.ini +++ b/qa/tox.ini @@ -10,7 +10,7 @@ commands=flake8 --select=F,E9 --exclude=venv,.tox [testenv:mypy] basepython = python3 -deps = mypy==0.782 +deps = mypy==0.790 commands = mypy {posargs:.} [testenv:import-tasks] diff --git a/src/cephadm/tox.ini b/src/cephadm/tox.ini index d8cd7c322a99d..17371260e9aaa 100644 --- a/src/cephadm/tox.ini +++ b/src/cephadm/tox.ini @@ -12,5 +12,5 @@ commands=pytest {posargs} [testenv:mypy] basepython = python3 -deps = mypy==0.782 +deps = mypy==0.790 commands = mypy --config-file ../mypy.ini {posargs:cephadm} diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index c4819ef30263a..b428efe7ab532 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -21,7 +21,8 @@ from .services.auth import JwtManager from .settings import Settings try: - from typing import Any, AnyStr, Callable, DefaultDict, Deque, Dict, List, Set, Tuple, Union + from typing import Any, AnyStr, Callable, DefaultDict, Deque, Dict, List, \ + Optional, Set, Tuple, Union except ImportError: pass # For typing only @@ -569,9 +570,9 @@ class Task(object): self.event = threading.Event() self.progress = None self.ret_value = None - self.begin_time = None - self.end_time = None - self.duration = 0 + self._begin_time: Optional[float] = None + self._end_time: Optional[float] = None + self.duration = 0.0 self.exception = None self.logger = logging.getLogger('task') self.lock = threading.Lock() @@ -595,7 +596,7 @@ class Task(object): assert not self.running self.executor.init(self) self.set_progress(0, in_lock=True) - self.begin_time = time.time() + self._begin_time = time.time() self.running = True self.executor.start() @@ -609,10 +610,10 @@ class Task(object): exception = ex with self.lock: assert self.running, "_complete cannot be called before _run" - self.end_time = now + self._end_time = now self.ret_value = ret_value self.exception = exception - self.duration = now - self.begin_time # type: ignore + self.duration = now - self.begin_time if not self.exception: self.set_progress(100, True) NotificationQueue.new_notification('cd_task_finished', self) @@ -661,6 +662,16 @@ class Task(object): if not in_lock: self.lock.release() + @property + def end_time(self) -> float: + assert self._end_time is not None + return self._end_time + + @property + def begin_time(self) -> float: + assert self._begin_time is not None + return self._begin_time + def build_url(host, scheme=None, port=None): """ diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index 77c7559a75cf6..bb9c62e880064 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -47,7 +47,7 @@ basepython = python3 deps = cython -rrequirements.txt - mypy==0.782 + mypy==0.790 commands = mypy --config-file=../../mypy.ini \ cephadm/module.py \ diff --git a/src/python-common/requirements.txt b/src/python-common/requirements.txt index d472610f62421..987dd0d2892d1 100644 --- a/src/python-common/requirements.txt +++ b/src/python-common/requirements.txt @@ -1,6 +1,6 @@ pytest >=2.1.3,<5; python_version < '3.5' mock; python_version < '3.3' -mypy==0.782; python_version >= '3' +mypy==0.790; python_version >= '3' pytest-mypy; python_version >= '3' pytest >= 2.1.3; python_version >= '3' pyyaml -- 2.39.5