Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f22b62e

Browse files
committed
#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.
1 parent 3191632 commit f22b62e

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

Lib/test/test_docxmlrpc.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,18 @@ def add(x, y):
5454
"""
5555
return x + y
5656

57+
def annotation(x: int):
58+
""" Use function annotations. """
59+
return x
60+
61+
class ClassWithAnnotation:
62+
def method_annotation(self, x: bytes):
63+
return x.decode()
64+
5765
serv.register_function(add)
5866
serv.register_function(lambda x, y: x-y)
67+
serv.register_function(annotation)
68+
serv.register_instance(ClassWithAnnotation())
5969

6070
while numrequests > 0:
6171
serv.handle_request()
@@ -177,10 +187,7 @@ def test_system_methods(self):
177187
b'method takes two integers as arguments'
178188
b'<br>\nand&nbsp;returns&nbsp;a&nbsp;double&nbsp;result.<br>\n&nbsp;'
179189
b'<br>\nThis&nbsp;server&nbsp;does&nbsp;NOT&nbsp;support&nbsp;system'
180-
b'.methodSignature.</tt></dd></dl>\n<dl><dt><a name="-test_method">'
181-
b'<strong>test_method</strong></a>(arg)</dt><dd><tt>Test&nbsp;'
182-
b'method\'s&nbsp;docs.&nbsp;This&nbsp;method&nbsp;truly&nbsp;does'
183-
b'&nbsp;very&nbsp;little.</tt></dd></dl>'), response)
190+
b'.methodSignature.</tt></dd></dl>'), response)
184191

185192
def test_autolink_dotted_methods(self):
186193
"""Test that selfdot values are made strong automatically in the
@@ -191,6 +198,18 @@ def test_autolink_dotted_methods(self):
191198
self.assertIn(b"""Try&nbsp;self.<strong>add</strong>,&nbsp;too.""",
192199
response.read())
193200

201+
def test_annotations(self):
202+
""" Test that annotations works as expected """
203+
self.client.request("GET", "/")
204+
response = self.client.getresponse()
205+
self.assertIn(
206+
(b'<dl><dt><a name="-annotation"><strong>annotation</strong></a>'
207+
b'(x: int)</dt><dd><tt>Use&nbsp;function&nbsp;annotations.</tt>'
208+
b'</dd></dl>\n<dl><dt><a name="-method_annotation"><strong>'
209+
b'method_annotation</strong></a>(x: bytes)</dt></dl>'),
210+
response.read())
211+
212+
194213
def test_main():
195214
support.run_unittest(DocXMLRPCHTTPGETServer)
196215

Lib/xmlrpc/server.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -756,20 +756,23 @@ def docroutine(self, object, name, mod=None,
756756
self.escape(anchor), self.escape(name))
757757

758758
if inspect.ismethod(object):
759-
args, varargs, varkw, defaults = inspect.getargspec(object)
759+
args = inspect.getfullargspec(object)
760760
# exclude the argument bound to the instance, it will be
761761
# confusing to the non-Python user
762762
argspec = inspect.formatargspec (
763-
args[1:],
764-
varargs,
765-
varkw,
766-
defaults,
763+
args.args[1:],
764+
args.varargs,
765+
args.varkw,
766+
args.defaults,
767+
annotations=args.annotations,
767768
formatvalue=self.formatvalue
768769
)
769770
elif inspect.isfunction(object):
770-
args, varargs, varkw, defaults = inspect.getargspec(object)
771+
args = inspect.getfullargspec(object)
771772
argspec = inspect.formatargspec(
772-
args, varargs, varkw, defaults, formatvalue=self.formatvalue)
773+
args.args, args.varargs, args.varkw, args.defaults,
774+
annotations=args.annotations,
775+
formatvalue=self.formatvalue)
773776
else:
774777
argspec = '(...)'
775778

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Core and Builtins
6464
Library
6565
-------
6666

67+
- Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
68+
if methods have annotations; it now correctly displays the annotations.
69+
6770
- Issue #17998: Fix an internal error in regular expression engine.
6871

6972
- Issue #17557: Fix os.getgroups() to work with the modified behavior of

0 commit comments

Comments
 (0)