Merge heads.

This commit is contained in:
R David Murray 2013-08-10 12:13:44 -04:00
commit 13f4cd6c10
3 changed files with 36 additions and 11 deletions

View File

@ -54,8 +54,18 @@ def server(evt, numrequests):
""" """
return x + y 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(add)
serv.register_function(lambda x, y: x-y) serv.register_function(lambda x, y: x-y)
serv.register_function(annotation)
serv.register_instance(ClassWithAnnotation())
while numrequests > 0: while numrequests > 0:
serv.handle_request() serv.handle_request()
@ -177,10 +187,7 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
b'method takes two integers as arguments' b'method takes two integers as arguments'
b'<br>\nand&nbsp;returns&nbsp;a&nbsp;double&nbsp;result.<br>\n&nbsp;' 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'<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'.methodSignature.</tt></dd></dl>'), response)
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)
def test_autolink_dotted_methods(self): def test_autolink_dotted_methods(self):
"""Test that selfdot values are made strong automatically in the """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.""", self.assertIn(b"""Try&nbsp;self.<strong>add</strong>,&nbsp;too.""",
response.read()) 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(): def test_main():
support.run_unittest(DocXMLRPCHTTPGETServer) support.run_unittest(DocXMLRPCHTTPGETServer)

View File

@ -756,20 +756,23 @@ class ServerHTMLDoc(pydoc.HTMLDoc):
self.escape(anchor), self.escape(name)) self.escape(anchor), self.escape(name))
if inspect.ismethod(object): 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 # exclude the argument bound to the instance, it will be
# confusing to the non-Python user # confusing to the non-Python user
argspec = inspect.formatargspec ( argspec = inspect.formatargspec (
args[1:], args.args[1:],
varargs, args.varargs,
varkw, args.varkw,
defaults, args.defaults,
annotations=args.annotations,
formatvalue=self.formatvalue formatvalue=self.formatvalue
) )
elif inspect.isfunction(object): elif inspect.isfunction(object):
args, varargs, varkw, defaults = inspect.getargspec(object) args = inspect.getfullargspec(object)
argspec = inspect.formatargspec( 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: else:
argspec = '(...)' argspec = '(...)'

View File

@ -24,6 +24,9 @@ Core and Builtins
Library Library
------- -------
- Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
if methods have annotations; it now correctly displays the annotations.
- Issue #18600: Added policy argument to email.message.Message.as_string, - Issue #18600: Added policy argument to email.message.Message.as_string,
and as_bytes and __bytes__ methods to Message. and as_bytes and __bytes__ methods to Message.