From a823ee6b1f5a8eb2030c1edf0a7014f86eb719ab Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Thu, 10 Dec 2020 15:53:00 +0100 Subject: [PATCH] mgr/cephadm: disallow_untyped_defs=True simplifies mypy.ini Signed-off-by: Sebastian Wagner --- src/mypy.ini | 19 +------------------ src/pybind/mgr/cephadm/migrations.py | 8 ++++---- src/pybind/mgr/cephadm/module.py | 2 +- src/pybind/mgr/cephadm/remotes.py | 8 +++++--- src/pybind/mgr/cephadm/template.py | 6 +++--- src/pybind/mgr/cephadm/utils.py | 6 +++--- 6 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/mypy.ini b/src/mypy.ini index cf8a8b5f4e893..53b2a5cfd94e7 100755 --- a/src/mypy.ini +++ b/src/mypy.ini @@ -17,24 +17,7 @@ ignore_missing_imports = True # This would require a cephfs.pyi file ignore_missing_imports = True - -[mypy-cephadm.services.*] - -disallow_untyped_defs = True - -[mypy-cephadm.upgrade.*] -disallow_untyped_defs = True - -[mypy-cephadm.serve.*] -disallow_untyped_defs = True - -[mypy-cephadm.inventory] -disallow_untyped_defs = True - -[mypy-cephadm.schedule] -disallow_untyped_defs = True - -[mypy-cephadm.module] +[mypy-cephadm.*] disallow_untyped_defs = True # Make cephadm and rook happy diff --git a/src/pybind/mgr/cephadm/migrations.py b/src/pybind/mgr/cephadm/migrations.py index 4837cb19aaf1a..ee16be58836db 100644 --- a/src/pybind/mgr/cephadm/migrations.py +++ b/src/pybind/mgr/cephadm/migrations.py @@ -36,20 +36,20 @@ class Migrations: # let's try to shortcut things here. self.migrate() - def set(self, val): + def set(self, val: int) -> None: self.mgr.set_module_option('migration_current', val) self.mgr.migration_current = val - def is_migration_ongoing(self): + def is_migration_ongoing(self) -> bool: return self.mgr.migration_current != LAST_MIGRATION - def verify_no_migration(self): + def verify_no_migration(self) -> None: if self.is_migration_ongoing(): # this is raised in module.serve() raise OrchestratorError( "cephadm migration still ongoing. Please wait, until the migration is complete.") - def migrate(self): + def migrate(self) -> None: if self.mgr.migration_current == 0: if self.migrate_0_1(): self.set(1) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 223612e542332..db7c83ed2513b 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -327,7 +327,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, self.allow_ptrace = False self.container_init = False self.prometheus_alerts_path = '' - self.migration_current = None + self.migration_current: Optional[int] = None self.config_dashboard = True self.manage_etc_ceph_ceph_conf = True self.registry_url: Optional[str] = None diff --git a/src/pybind/mgr/cephadm/remotes.py b/src/pybind/mgr/cephadm/remotes.py index d8cda4e9d9c94..9165a65048cc1 100644 --- a/src/pybind/mgr/cephadm/remotes.py +++ b/src/pybind/mgr/cephadm/remotes.py @@ -1,8 +1,9 @@ # ceph-deploy ftw import os -import errno -import tempfile -import shutil +try: + from typing import Optional +except ImportError: + pass PYTHONS = ['python3', 'python2', 'python'] PATH = [ @@ -16,6 +17,7 @@ PATH = [ def choose_python(): + # type: () -> Optional[str] for e in PYTHONS: for b in PATH: p = os.path.join(b, e) diff --git a/src/pybind/mgr/cephadm/template.py b/src/pybind/mgr/cephadm/template.py index 778bc26c0e771..c59df3f9fb3a6 100644 --- a/src/pybind/mgr/cephadm/template.py +++ b/src/pybind/mgr/cephadm/template.py @@ -26,7 +26,7 @@ class TemplateEngine: class Jinja2Engine(TemplateEngine): - def __init__(self): + def __init__(self) -> None: self.env = Environment( loader=PackageLoader('cephadm', 'templates'), autoescape=select_autoescape(['html', 'xml'], default_for_string=False), @@ -46,7 +46,7 @@ class Jinja2Engine(TemplateEngine): except j2_exceptions.TemplateNotFound as e: raise TemplateNotFoundError(e.message) - def render_plain(self, source, context): + def render_plain(self, source: str, context: Optional[dict]) -> str: try: template = self.env.from_string(source) if context is None: @@ -68,7 +68,7 @@ class TemplateMgr: def render(self, name: str, context: Optional[dict] = None, - managed_context=True, + managed_context: bool = True, host: Optional[str] = None) -> str: """Render a string from a template with context. diff --git a/src/pybind/mgr/cephadm/utils.py b/src/pybind/mgr/cephadm/utils.py index 03a28fbd9efe3..752031a5037e1 100644 --- a/src/pybind/mgr/cephadm/utils.py +++ b/src/pybind/mgr/cephadm/utils.py @@ -4,7 +4,7 @@ import json import datetime from enum import Enum from functools import wraps -from typing import Optional, Callable, TypeVar, List, NewType, TYPE_CHECKING +from typing import Optional, Callable, TypeVar, List, NewType, TYPE_CHECKING, Any from orchestrator import OrchestratorError if TYPE_CHECKING: @@ -41,7 +41,7 @@ def name_to_config_section(name: str) -> ConfEntity: def forall_hosts(f: Callable[..., T]) -> Callable[..., List[T]]: @wraps(f) - def forall_hosts_wrapper(*args) -> List[T]: + def forall_hosts_wrapper(*args: Any) -> List[T]: from cephadm.module import CephadmOrchestrator # Some weired logic to make calling functions with multiple arguments work. @@ -53,7 +53,7 @@ def forall_hosts(f: Callable[..., T]) -> Callable[..., List[T]]: else: assert 'either f([...]) or self.f([...])' - def do_work(arg): + def do_work(arg: Any) -> T: if not isinstance(arg, tuple): arg = (arg, ) try: -- 2.39.5