(original) (raw)

changeset: 85096:bc49e82ee013 branch: 3.3 parent: 85090:28c756093a63 user: R David Murray rdmurray@bitdance.com date: Sat Aug 10 12:01:47 2013 -0400 files: Lib/test/test_docxmlrpc.py Lib/xmlrpc/server.py Misc/NEWS description: #8112: Update the documenting xmlrpc server to use getfullargspec. Before this patch it would raise an error when trying to display documentation for a method that used annotations. Patch by Claudiu Popa. diff -r 28c756093a63 -r bc49e82ee013 Lib/test/test_docxmlrpc.py --- a/Lib/test/test_docxmlrpc.py Sat Aug 10 18:37:05 2013 +0300 +++ b/Lib/test/test_docxmlrpc.py Sat Aug 10 12:01:47 2013 -0400 @@ -54,8 +54,18 @@ """ 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 @@ b'method takes two integers as arguments' b'
\nand returns a double result.
\n ' b'
\nThis server does NOT support system' - b'.methodSignature.\n

' - b'test_method(arg)

Test ' - b'method\'s docs. This method truly does' - b' very little.

'), response) + b'.methodSignature.'), response) def test_autolink_dotted_methods(self): """Test that selfdot values are made strong automatically in the @@ -191,6 +198,18 @@ self.assertIn(b"""Try self.add, too.""", response.read()) + def test_annotations(self): + """ Test that annotations works as expected """ + self.client.request("GET", "/") + response = self.client.getresponse() + self.assertIn( + (b'

annotation' + b'(x: int)

Use function annotations.' + b'

\n

' + b'method_annotation(x: bytes)

'), + response.read()) + + def test_main(): support.run_unittest(DocXMLRPCHTTPGETServer) diff -r 28c756093a63 -r bc49e82ee013 Lib/xmlrpc/server.py --- a/Lib/xmlrpc/server.py Sat Aug 10 18:37:05 2013 +0300 +++ b/Lib/xmlrpc/server.py Sat Aug 10 12:01:47 2013 -0400 @@ -756,20 +756,23 @@ 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 = '(...)' diff -r 28c756093a63 -r bc49e82ee013 Misc/NEWS --- a/Misc/NEWS Sat Aug 10 18:37:05 2013 +0300 +++ b/Misc/NEWS Sat Aug 10 12:01:47 2013 -0400 @@ -64,6 +64,9 @@ 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 /rdmurray@bitdance.com