From: Sebastian Wagner Date: Tue, 15 Jun 2021 08:19:40 +0000 (+0200) Subject: mgr/orch: fix mypy errors X-Git-Tag: v17.1.0~1650^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=90c9980e8ff2fb975e70c61d5eb7578385876065;p=ceph.git mgr/orch: fix mypy errors Fixes: ``` orchestrator/__init__.py:6: note: In module imported here: orchestrator/_interface.py: note: In member "yaml_representer" of class "DaemonDescription": orchestrator/_interface.py:1039: error: Argument 1 to "represent_dict" of "SafeRepresenter" has incompatible type "ItemsView[Any, Any]"; expected "Mapping[Any, Any]" orchestrator/_interface.py: note: In member "yaml_representer" of class "ServiceDescription": orchestrator/_interface.py:1178: error: Argument 1 to "represent_dict" of "SafeRepresenter" has incompatible type "ItemsView[Any, Any]"; expected "Mapping[Any, Any]" orchestrator/_interface.py: note: At top level: orchestrator/_interface.py:1181: error: Argument 2 to "add_representer" has incompatible type "Callable[[SafeDumper, DaemonDescription], Any]"; expected "Callable[[SafeDumper, ServiceDescription], Node]" Found 3 errors in 1 file (checked 29 source files) ``` Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 773db30be8f8..9c18351599f3 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -18,7 +18,7 @@ from contextlib import contextmanager from functools import wraps, reduce from typing import TypeVar, Generic, List, Optional, Union, Tuple, Iterator, Callable, Any, \ - Sequence, Dict, cast + Sequence, Dict, cast, Mapping try: from typing import Protocol # Protocol was added in Python 3.8 @@ -1036,7 +1036,7 @@ class DaemonDescription(object): @staticmethod def yaml_representer(dumper: 'yaml.SafeDumper', data: 'DaemonDescription') -> Any: - return dumper.represent_dict(data.to_json().items()) + return dumper.represent_dict(cast(Mapping, data.to_json().items())) yaml.add_representer(DaemonDescription, DaemonDescription.yaml_representer) @@ -1174,8 +1174,8 @@ class ServiceDescription(object): return cls(spec=spec, events=events, **c_status) @staticmethod - def yaml_representer(dumper: 'yaml.SafeDumper', data: 'DaemonDescription') -> Any: - return dumper.represent_dict(data.to_json().items()) + def yaml_representer(dumper: 'yaml.SafeDumper', data: 'ServiceDescription') -> Any: + return dumper.represent_dict(cast(Mapping, data.to_json().items())) yaml.add_representer(ServiceDescription, ServiceDescription.yaml_representer)