#1987 Add doc string for virtual methods
Merged 5 months ago by tkopecek. Opened 5 months ago by tkopecek.
tkopecek/koji issue1533  into  master

file modified
+36 -3

@@ -2178,14 +2178,44 @@ 

      # some magic to bind an XML-RPC method to an RPC server.

      # supports "nested" methods (e.g. examples.getStateName)

      # supports named arguments (if server does)

-     def __init__(self, func, name):

+     def __init__(self, func, name, session=None):

          self.__func = func

          self.__name = name

+         self.__session = session

+ 

      def __getattr__(self, name):

          return type(self)(self.__func, "%s.%s" % (self.__name, name))

+ 

      def __call__(self, *args, **opts):

          return self.__func(self.__name, args, opts)

  

+     @property

+     def __doc__(self):

+         if self.__session is None:

+             # There could be potentially session-less object

+             return None

+         # try to fetch API docs

+         if self.__session._apidoc is None:

+             try:

+                 self.__session._apidoc = dict(

+                     [(f["name"], f) for f in self.__func("_listapi", [], {})]

+                 )

+             except:

+                 self.__session._apidoc = {}

+ 

+         funcdoc = self.__session._apidoc.get(self.__name)

+         if funcdoc:

+             # add argument description to docstring since the

+             # call signature is not updated, yet

+             argdesc = funcdoc["name"] + funcdoc["argdesc"] + "\n"

+             doc = funcdoc["doc"]

+             if doc:

+                 return argdesc + doc

+             else:

+                 return argdesc

+         else:

+             return None

+ 

  

  def grab_session_options(options):

      """Convert optparse options to a dict that ClientSession can handle;

@@ -2232,6 +2262,7 @@ 

              opts = {}

          else:

              opts = opts.copy()

+         self._apidoc = None

          self.baseurl = baseurl

          self.opts = opts

          self.authtype = None

@@ -2795,7 +2826,9 @@ 

      def __getattr__(self, name):

          #if name[:1] == '_':

          #    raise AttributeError("no attribute %r" % name)

-         return VirtualMethod(self._callMethod, name)

+         if name == '_apidoc':

+             return self.__dict__['_apidoc']

+         return VirtualMethod(self._callMethod, name, self)

  

      def fastUpload(self, localfile, path, name=None, callback=None, blocksize=None, overwrite=False, volume=None):

          if blocksize is None:

@@ -3054,7 +3087,7 @@ 

          self._calls = []

  

      def __getattr__(self, name):

-         return VirtualMethod(self._callMethod, name)

+         return VirtualMethod(self._callMethod, name, self._session)

  

      def _callMethod(self, name, args, kwargs=None, retry=True):

          """Add a new call to the multicall"""

Additional work on #922. Cache is now per session. Anyway, you can see __doc__ only directly e.g. print(session.listTagged.__doc__), not interactively via help(session.listTagged). There you'll still see VirtualMethod desc. Any idea, how to do it elegantly?

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

5 months ago

pretty please pagure-ci rebuild

5 months ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

5 months ago

Commit 5f026cd fixes this pull-request

Pull-Request has been merged by tkopecek

5 months ago