| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,8 +54,18 @@ def add(x, y): | |||
| 54 | 54 | """ | |
| 55 | 55 | return x + y | |
| 56 | 56 | ||
| 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 | + | ||
| 57 | 65 | serv.register_function(add) | |
| 58 | 66 | serv.register_function(lambda x, y: x-y) | |
| 67 | + serv.register_function(annotation) | ||
| 68 | + serv.register_instance(ClassWithAnnotation()) | ||
| 59 | 69 | ||
| 60 | 70 | while numrequests > 0: | |
| 61 | 71 | serv.handle_request() | |
@@ -177,10 +187,7 @@ def test_system_methods(self): | |||
| 177 | 187 | b'method takes two integers as arguments' | |
| 178 | 188 | b'<br>\nand returns a double result.<br>\n ' | |
| 179 | 189 | b'<br>\nThis 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) | ||
| 184 | 191 | ||
| 185 | 192 | def test_autolink_dotted_methods(self): | |
| 186 | 193 | """Test that selfdot values are made strong automatically in the | |
@@ -191,6 +198,18 @@ def test_autolink_dotted_methods(self): | |||
| 191 | 198 | self.assertIn(b"""Try self.<strong>add</strong>, too.""", | |
| 192 | 199 | response.read()) | |
| 193 | 200 | ||
| 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 | + | ||
| 194 | 213 | def test_main(): | |
| 195 | 214 | support.run_unittest(DocXMLRPCHTTPGETServer) | |
| 196 | 215 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -756,20 +756,23 @@ def docroutine(self, object, name, mod=None, | |||
| 756 | 756 | self.escape(anchor), self.escape(name)) | |
| 757 | 757 | ||
| 758 | 758 | if inspect.ismethod(object): | |
| 759 | - args, varargs, varkw, defaults = inspect.getargspec(object) | ||
| 759 | + args = inspect.getfullargspec(object) | ||
| 760 | 760 | # exclude the argument bound to the instance, it will be | |
| 761 | 761 | # confusing to the non-Python user | |
| 762 | 762 | 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, | ||
| 767 | 768 | formatvalue=self.formatvalue | |
| 768 | 769 | ) | |
| 769 | 770 | elif inspect.isfunction(object): | |
| 770 | - args, varargs, varkw, defaults = inspect.getargspec(object) | ||
| 771 | + args = inspect.getfullargspec(object) | ||
| 771 | 772 | 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) | ||
| 773 | 776 | else: | |
| 774 | 777 | argspec = '(...)' | |
| 775 | 778 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,9 @@ Core and Builtins | |||
| 24 | 24 | Library | |
| 25 | 25 | ------- | |
| 26 | 26 | ||
| 27 | + - Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error | ||
| 28 | + if methods have annotations; it now correctly displays the annotations. | ||
| 29 | + | ||
| 27 | 30 | - Issue #18600: Added policy argument to email.message.Message.as_string, | |
| 28 | 31 | and as_bytes and __bytes__ methods to Message. | |
| 29 | 32 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments