Close #8924: autodoc: Support bound argument for TypeVar

This commit is contained in:
Takeshi KOMIYA 2021-02-24 22:51:06 +09:00
parent faa71ee26d
commit a39cf57717
4 changed files with 14 additions and 0 deletions

View File

@ -55,6 +55,7 @@ Deprecated
Features added
--------------
* #8924: autodoc: Support ``bound`` argument for TypeVar
* #4826: py domain: Add ``:canonical:`` option to python directives to describe
the location where the object is defined
* #7784: i18n: The alt text for image is translated by default (without

View File

@ -1812,6 +1812,8 @@ class TypeVarMixin(DataDocumenterMixinBase):
attrs = [repr(self.object.__name__)]
for constraint in self.object.__constraints__:
attrs.append(stringify_typehint(constraint))
if self.object.__bound__:
attrs.append(r"bound=\ " + restify(self.object.__bound__))
if self.object.__covariant__:
attrs.append("covariant=True")
if self.object.__contravariant__:

View File

@ -17,6 +17,9 @@ T5 = TypeVar("T5", contravariant=True)
#: T6
T6 = NewType("T6", int)
#: T7
T7 = TypeVar("T7", bound=int)
class Class:
#: T1

View File

@ -1993,6 +1993,14 @@ def test_autodoc_TypeVar(app):
'',
' alias of :class:`int`',
'',
'',
'.. py:data:: T7',
' :module: target.typevar',
'',
' T7',
'',
" alias of TypeVar('T7', bound=\\ :class:`int`)",
'',
]