* Show docstring for special forms.
* Show docstring for special generic aliases.
* Show documentation for __origin__ for generic aliases.
grammar was much more restrictive. See :pep:`614` for details.
(Contributed by Brandt Bucher in :issue:`39702`.)
+* Improved help for the :mod:`typing` module. Docstrings are now shown for
+ all special forms and special generic aliases (like ``Union`` and ``List``).
+ Using :func:`help` with generic alias like ``List[int]`` will show the help
+ for the correspondent concrete type (``list`` in this case).
+ (Contributed by Serhiy Storchaka in :issue:`40257`.)
+
New Modules
===========
if not doc:
doc = getdoc(object)
if doc:
- line += '\n' + self.indent(str(doc))
+ line += '\n' + self.indent(str(doc)) + '\n'
return line
class _PlainTextDoc(TextDoc):
inspect.getdoc(object)):
# If the passed object is a piece of data or an instance,
# document its available methods instead of its value.
- object = type(object)
- desc += ' object'
+ if hasattr(object, '__origin__'):
+ object = object.__origin__
+ else:
+ object = type(object)
+ desc += ' object'
return title % desc + '\n\n' + renderer.document(object, name)
def doc(thing, title='Python Library Documentation: %s', forceload=0,
X.attr.__doc__ = 'Custom descriptor'
self.assertEqual(self._get_summary_lines(X.attr), """\
<test.test_pydoc.TestDescriptions.test_custom_non_data_descriptor.<locals>.Descr object>
- Custom descriptor""")
+ Custom descriptor
+""")
X.attr.__name__ = 'foo'
self.assertEqual(self._get_summary_lines(X.attr), """\
self._name = name
self._doc = doc
+ @property
+ def __doc__(self):
+ return self._doc
+
def __eq__(self, other):
if not isinstance(other, _SpecialForm):
return NotImplemented
self.__slots__ = None # This is not documented.
if not name:
self.__module__ = origin.__module__
+ if special:
+ self.__doc__ = f'A generic version of {origin.__module__}.{origin.__qualname__}'
@_tp_cache
def __getitem__(self, params):
--- /dev/null
+Improved help for the :mod:`typing` module. Docstrings are now shown for all
+special forms and special generic aliases (like ``Union`` and ``List``).
+Using ``help()`` with generic alias like ``List[int]`` will show the help
+for the correspondent concrete type (``list`` in this case).