From: John Mulligan Date: Mon, 11 Apr 2022 18:46:37 +0000 (-0400) Subject: pybind/mgr: change to private _load_func_metadata classmethod X-Git-Tag: v18.0.0~841^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8c7876146bb7d579cd000049611ae999a8bc1963;p=ceph.git pybind/mgr: change to private _load_func_metadata classmethod The load_func_metadata had exactly one use in the codebase, the store_func_metadata method. It was also a staticmethod that referred to a property of it's class. This change makes the function "private" by renaming it to _load_func_metadata, removing it from the public "surface area" of the type. It changes it to a classmethod so that it would work correctly if used from a subclass of CLICommand. Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 20b019156fdf..1aa50b049d3f 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -346,8 +346,8 @@ class CLICommand(object): KNOWN_ARGS = '_', 'self', 'mgr', 'inbuf', 'return' - @staticmethod - def load_func_metadata(f: HandlerFuncType) -> Tuple[str, Dict[str, Any], int, str]: + @classmethod + def _load_func_metadata(cls: Any, f: HandlerFuncType) -> Tuple[str, Dict[str, Any], int, str]: desc = (inspect.getdoc(f) or '').replace('\n', ' ') full_argspec = inspect.getfullargspec(f) arg_spec = full_argspec.annotations @@ -357,7 +357,7 @@ class CLICommand(object): args = [] positional = True for index, arg in enumerate(full_argspec.args): - if arg in CLICommand.KNOWN_ARGS: + if arg in cls.KNOWN_ARGS: continue if arg == '_end_positional_': positional = False @@ -381,7 +381,7 @@ class CLICommand(object): def store_func_metadata(self, f: HandlerFuncType) -> None: self.desc, self.arg_spec, self.first_default, self.args = \ - self.load_func_metadata(f) + self._load_func_metadata(f) def __call__(self, func: HandlerFuncType) -> HandlerFuncType: self.store_func_metadata(func)