]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: change to private _load_func_metadata classmethod
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 11 Apr 2022 18:46:37 +0000 (14:46 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 13 May 2022 14:42:00 +0000 (10:42 -0400)
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 <jmulligan@redhat.com>
src/pybind/mgr/mgr_module.py

index 20b019156fdf38c87b785b6b8472af913198cd1f..1aa50b049d3f9b4c8038dbd0cc8161c0a179297f 100644 (file)
@@ -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)