From 5fe9bf04c46bfcbb4008d8d2a51b74c6c1693ec3 Mon Sep 17 00:00:00 2001 From: rpm-build Date: Tue, 22 Aug 2023 18:25:34 +0800 Subject: [PATCH] Fix typing in resource_agent package --- mypy.ini | 10 +++++----- pcs/lib/resource_agent/error.py | 4 ++-- pcs/lib/resource_agent/facade.py | 12 +++++++----- pcs/lib/resource_agent/types.py | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/mypy.ini b/mypy.ini index f34b513..a3f7d07 100644 --- a/mypy.ini +++ b/mypy.ini @@ -48,19 +48,19 @@ disallow_untyped_defs = True # this is a temporary solution for legacy code disallow_untyped_defs = False -[mypy-pcs.common.ssl] +[mypy-pcs.common.services.*] disallow_untyped_defs = True disallow_untyped_calls = True -[mypy-pcs.common.types] +[mypy-pcs.common.ssl] disallow_untyped_defs = True disallow_untyped_calls = True -[mypy-pcs.common.validate] +[mypy-pcs.common.types] disallow_untyped_defs = True disallow_untyped_calls = True -[mypy-pcs.common.services.*] +[mypy-pcs.common.validate] disallow_untyped_defs = True disallow_untyped_calls = True @@ -113,7 +113,7 @@ disallow_untyped_defs = True disallow_untyped_defs = True disallow_untyped_calls = True -[mypy-pcs.lib.resource_agent] +[mypy-pcs.lib.resource_agent.*] disallow_untyped_defs = True disallow_untyped_calls = True diff --git a/pcs/lib/resource_agent/error.py b/pcs/lib/resource_agent/error.py index d417833..f61f196 100644 --- a/pcs/lib/resource_agent/error.py +++ b/pcs/lib/resource_agent/error.py @@ -17,13 +17,13 @@ class AgentNameGuessFoundMoreThanOne(ResourceAgentError): self.names_found = names_found @property - def searched_name(self): + def searched_name(self) -> str: return self.agent_name class AgentNameGuessFoundNone(ResourceAgentError): @property - def searched_name(self): + def searched_name(self) -> str: return self.agent_name diff --git a/pcs/lib/resource_agent/facade.py b/pcs/lib/resource_agent/facade.py index 4dbb59b..d5a28f3 100644 --- a/pcs/lib/resource_agent/facade.py +++ b/pcs/lib/resource_agent/facade.py @@ -1,6 +1,6 @@ from collections import defaultdict from dataclasses import replace as dc_replace -from typing import Dict, Iterable, List, Optional, Set +from typing import Dict, Iterable, List, Optional, Set, cast from pcs.common import reports from pcs.lib import validate @@ -12,6 +12,7 @@ from .name import name_to_void_metadata from .ocf_transform import ocf_version_to_ocf_unified from .pcs_transform import get_additional_trace_parameters, ocf_unified_to_pcs from .types import ( + FakeAgentName, ResourceAgentMetadata, ResourceAgentName, ResourceAgentParameter, @@ -154,7 +155,7 @@ class ResourceAgentFacade: return validators @property - def _validator_option_type(self): + def _validator_option_type(self) -> str: return "stonith" if self.metadata.name.is_stonith else "resource" def _get_all_params_deprecated_by(self) -> Dict[str, Set[str]]: @@ -185,7 +186,7 @@ class ResourceAgentFacadeFactory: ) -> None: self._runner = runner self._report_processor = report_processor - self._fenced_metadata = None + self._fenced_metadata: Optional[ResourceAgentMetadata] = None def facade_from_parsed_name( self, name: ResourceAgentName @@ -226,7 +227,7 @@ class ResourceAgentFacadeFactory: ) return ResourceAgentFacade(metadata, additional_parameters) - def _get_fenced_parameters(self): + def _get_fenced_parameters(self) -> List[ResourceAgentParameter]: if self._fenced_metadata is None: agent_name = ResourceAgentName( const.FAKE_AGENT_STANDARD, None, const.PACEMAKER_FENCED @@ -237,7 +238,8 @@ class ResourceAgentFacadeFactory: parse_metadata( agent_name, load_fake_agent_metadata( - self._runner, agent_name.type + self._runner, + cast(FakeAgentName, agent_name.type), ), ) ) diff --git a/pcs/lib/resource_agent/types.py b/pcs/lib/resource_agent/types.py index ffa5a51..d045e01 100644 --- a/pcs/lib/resource_agent/types.py +++ b/pcs/lib/resource_agent/types.py @@ -26,11 +26,11 @@ class ResourceAgentName: return ":".join(filter(None, [self.standard, self.provider, self.type])) @property - def is_pcmk_fake_agent(self): + def is_pcmk_fake_agent(self) -> bool: return self.standard == _FAKE_AGENT_STANDARD @property - def is_stonith(self): + def is_stonith(self) -> bool: return self.standard == "stonith" def to_dto(self) -> ResourceAgentNameDto: -- 2.41.0