diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_pydoc.py | 13 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 2380095..2923d6d 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1140,6 +1140,8 @@ def getargvalues(frame): return ArgInfo(args, varargs, varkw, frame.f_locals) def formatannotation(annotation, base_module=None): + if getattr(annotation, '__module__', None) == 'typing': + return repr(annotation).replace('typing.', '') if isinstance(annotation, type): if annotation.__module__ in ('builtins', base_module): return annotation.__qualname__ diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 5174d56..ed438d5 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -15,6 +15,7 @@ import string import test.support import time import types +import typing import unittest import urllib.parse import xml.etree @@ -820,6 +821,18 @@ class TestDescriptions(unittest.TestCase): expected = 'C in module %s object' % __name__ self.assertIn(expected, pydoc.render_doc(c)) + def test_typing_pydoc(self): + def foo(data: typing.List[typing.Any], + x: int) -> typing.Iterator[typing.Tuple[int, typing.Any]]: + ... + T = typing.TypeVar('T') + class C(typing.Generic[T], typing.Mapping[int, str]): ... + self.assertEqual(pydoc.render_doc(foo).splitlines()[-1], + 'f\x08fo\x08oo\x08o(data:List[Any], x:int)' + ' -> Iterator[Tuple[int, Any]]') + self.assertEqual(pydoc.render_doc(C).splitlines()[2], + 'class C\x08C(typing.Mapping)') + def test_builtin(self): for name in ('str', 'str.translate', 'builtins.str', 'builtins.str.translate'): |