@@ -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>\n and returns a double result.<br>\n '
179189 b'<br>\n This server does NOT support 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 '
182- b'method\' s docs. This method truly does'
183- b' very 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 self.<strong>add</strong>, 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 function 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+
194213def test_main ():
195214 support .run_unittest (DocXMLRPCHTTPGETServer )
196215
0 commit comments