|
26 | 26 | _FunctionDefProperties, |
27 | 27 | _ItemProperties, |
28 | 28 | _ModuleProperties, |
| 29 | + _TypeStatementProperties, |
29 | 30 | ) |
30 | 31 | from sphinx.ext.autodoc._sentinels import ( |
31 | 32 | RUNTIME_INSTANCE_ATTRIBUTE, |
@@ -774,6 +775,34 @@ def _load_object_by_name( |
774 | 775 | _obj_repr_rst=inspect.object_description(obj), |
775 | 776 | _obj_type_annotation=type_annotation, |
776 | 777 | ) |
| 778 | + elif objtype == 'type': |
| 779 | + obj_module_name = getattr(obj, '__module__', module_name) |
| 780 | + if obj_module_name != module_name and module_name.startswith(obj_module_name): |
| 781 | + bases = module_name[len(obj_module_name) :].strip('.').split('.') |
| 782 | + parts = tuple(bases) + parts |
| 783 | + module_name = obj_module_name |
| 784 | + |
| 785 | + if config.autodoc_typehints_format == 'short': |
| 786 | + mode = 'smart' |
| 787 | + else: |
| 788 | + mode = 'fully-qualified-except-typing' |
| 789 | + short_literals = config.python_display_short_literal_types |
| 790 | + ann = stringify_annotation( |
| 791 | + obj.__value__, |
| 792 | + mode, # type: ignore[arg-type] |
| 793 | + short_literals=short_literals, |
| 794 | + ) |
| 795 | + props = _TypeStatementProperties( |
| 796 | + obj_type=objtype, |
| 797 | + module_name=module_name, |
| 798 | + parts=parts, |
| 799 | + docstring_lines=(), |
| 800 | + _obj=obj, |
| 801 | + _obj___module__=get_attr(obj, '__module__', None), |
| 802 | + _obj___name__=getattr(obj, '__name__', None), |
| 803 | + _obj___qualname__=getattr(obj, '__qualname__', None), |
| 804 | + _obj___value__=ann, |
| 805 | + ) |
777 | 806 | else: |
778 | 807 | props = _ItemProperties( |
779 | 808 | obj_type=objtype, |
@@ -912,7 +941,7 @@ def _resolve_name( |
912 | 941 | ) |
913 | 942 | return (path or '') + base, () |
914 | 943 |
|
915 | | - if objtype in {'class', 'exception', 'function', 'decorator', 'data'}: |
| 944 | + if objtype in {'class', 'exception', 'function', 'decorator', 'data', 'type'}: |
916 | 945 | if module_name is not None: |
917 | 946 | return module_name, (*parents, base) |
918 | 947 | if path: |
|
0 commit comments