]> git.apps.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)
committerAdam King <adking@redhat.com>
Sat, 21 May 2022 23:21:35 +0000 (19:21 -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>
(cherry picked from commit 8c7876146bb7d579cd000049611ae999a8bc1963)

src/pybind/mgr/mgr_module.py

index d1076b51be81d252c23f31f05349e556f1f67d84..f8f85b7172d82ce19bffeca327e3ed36c6f9b9f6 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)