]> granicus.if.org Git - python/commitdiff
#8112: Update the documenting xmlrpc server to use getfullargspec.
authorR David Murray <rdmurray@bitdance.com>
Sat, 10 Aug 2013 16:01:47 +0000 (12:01 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sat, 10 Aug 2013 16:01:47 +0000 (12:01 -0400)
Before this patch it would raise an error when trying to display
documentation for a method that used annotations.

Patch by Claudiu Popa.

Lib/test/test_docxmlrpc.py
Lib/xmlrpc/server.py
Misc/NEWS

index d6ca45847ecf8db0d9b57b315d050a5c2ee14c0e..7086d9a6a1223b2ca1622a69f6c8cd3c415e9472 100644 (file)
@@ -54,8 +54,18 @@ def server(evt, numrequests):
             """
             return x + y
 
+        def annotation(x: int):
+            """ Use function annotations. """
+            return x
+
+        class ClassWithAnnotation:
+            def method_annotation(self, x: bytes):
+                return x.decode()
+
         serv.register_function(add)
         serv.register_function(lambda x, y: x-y)
+        serv.register_function(annotation)
+        serv.register_instance(ClassWithAnnotation())
 
         while numrequests > 0:
             serv.handle_request()
@@ -177,10 +187,7 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
              b'method&nbsp;takes&nbsp;two&nbsp;integers&nbsp;as&nbsp;arguments'
              b'<br>\nand&nbsp;returns&nbsp;a&nbsp;double&nbsp;result.<br>\n&nbsp;'
              b'<br>\nThis&nbsp;server&nbsp;does&nbsp;NOT&nbsp;support&nbsp;system'
-             b'.methodSignature.</tt></dd></dl>\n<dl><dt><a name="-test_method">'
-             b'<strong>test_method</strong></a>(arg)</dt><dd><tt>Test&nbsp;'
-             b'method\'s&nbsp;docs.&nbsp;This&nbsp;method&nbsp;truly&nbsp;does'
-             b'&nbsp;very&nbsp;little.</tt></dd></dl>'), response)
+             b'.methodSignature.</tt></dd></dl>'), response)
 
     def test_autolink_dotted_methods(self):
         """Test that selfdot values are made strong automatically in the
@@ -191,6 +198,18 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
         self.assertIn(b"""Try&nbsp;self.<strong>add</strong>,&nbsp;too.""",
                       response.read())
 
+    def test_annotations(self):
+        """ Test that annotations works as expected """
+        self.client.request("GET", "/")
+        response = self.client.getresponse()
+        self.assertIn(
+            (b'<dl><dt><a name="-annotation"><strong>annotation</strong></a>'
+             b'(x: int)</dt><dd><tt>Use&nbsp;function&nbsp;annotations.</tt>'
+             b'</dd></dl>\n<dl><dt><a name="-method_annotation"><strong>'
+             b'method_annotation</strong></a>(x: bytes)</dt></dl>'),
+            response.read())
+
+
 def test_main():
     support.run_unittest(DocXMLRPCHTTPGETServer)
 
index 54e172670b11f365cf15e7c86aaefde5b9a1d897..78ca4e0a4afcae46dbf49de9751892c8d11538f6 100644 (file)
@@ -756,20 +756,23 @@ class ServerHTMLDoc(pydoc.HTMLDoc):
             self.escape(anchor), self.escape(name))
 
         if inspect.ismethod(object):
-            args, varargs, varkw, defaults = inspect.getargspec(object)
+            args = inspect.getfullargspec(object)
             # exclude the argument bound to the instance, it will be
             # confusing to the non-Python user
             argspec = inspect.formatargspec (
-                    args[1:],
-                    varargs,
-                    varkw,
-                    defaults,
+                    args.args[1:],
+                    args.varargs,
+                    args.varkw,
+                    args.defaults,
+                    annotations=args.annotations,
                     formatvalue=self.formatvalue
                 )
         elif inspect.isfunction(object):
-            args, varargs, varkw, defaults = inspect.getargspec(object)
+            args = inspect.getfullargspec(object)
             argspec = inspect.formatargspec(
-                args, varargs, varkw, defaults, formatvalue=self.formatvalue)
+                args.args, args.varargs, args.varkw, args.defaults,
+                annotations=args.annotations,
+                formatvalue=self.formatvalue)
         else:
             argspec = '(...)'
 
index d6a645d8870dec262b870fcbf7d1d47cc49b2b4b..635a925970f53b6198fd83464d88e1cfb9be165d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -64,6 +64,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
+  if methods have annotations; it now correctly displays the annotations.
+
 - Issue #17998: Fix an internal error in regular expression engine.
 
 - Issue #17557: Fix os.getgroups() to work with the modified behavior of