From 7c8e3e88d1e3700d9e27d63b35ee5a8433620181 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 29 Jan 2020 20:46:45 +0800 Subject: [PATCH] mgr/cephadm: init attrs created by settattr() to address the test falure caused by mypy: ``` mypy run-test: commands[0] | mypy --config-file=../../mypy.ini ansible/module.py cephadm/module.py mgr_module.py mgr_util.py orchestrator.py orchestrator_cli/module.py rook/module.py test_orchestrator/module.py cephadm/module.py: note: In member "_check_for_strays" of class "CephadmOrchestrator": cephadm/module.py:596: error: "CephadmOrchestrator" has no attribute "warn_on_stray_hosts" cephadm/module.py:596: error: "CephadmOrchestrator" has no attribute "warn_on_stray_services" cephadm/module.py:599: error: "CephadmOrchestrator" has no attribute "warn_on_stray_services" Found 3 errors in 1 file (checked 8 source files) ``` see also https://github.com/python/mypy/issues/5719 Signed-off-by: Kefu Chai --- src/pybind/mgr/cephadm/module.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index d5a44a00d42..ba1ffca3ab0 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -8,8 +8,9 @@ from functools import wraps import string try: from typing import List, Dict, Optional, Callable, TypeVar, Type, Any + from typing import TYPE_CHECKING except ImportError: - pass # just for type checking + TYPE_CHECKING = False # just for type checking import datetime @@ -331,6 +332,15 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): self.run = True self.event = Event() + # for mypy which does not run the code + if TYPE_CHECKING: + self.ssh_config_file = None # type: Optional[str] + self.inventory_cache_timeout = 0 + self.service_cache_timeout = 0 + self.mode = '' + self.container_image_base = '' + self.warn_on_stray_hosts = True + self.warn_on_stray_services = True self.config_notify() path = self.get_ceph_option('cephadm_path') -- 2.39.5