Skip to content

Commit 1668f92

Browse files
committed
fix: exception templates and nested args
1 parent e68622d commit 1668f92

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

autoapi/mappers/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,12 @@ def output_child_rst(self, obj, obj_parent, detail_dir, source_suffix):
334334
if not obj.display:
335335
return
336336

337-
# Skip nested cases like functions in functions or clases in clases
338-
if obj.type == obj_parent.type:
337+
# HACK: skip nested cases like functions in functions or clases in clases
338+
# Turns out that exceptions in Python have a property named "args" which
339+
# is a "class" type of "BaseException"
340+
is_same_type_as_parent = obj.type == obj_parent.type
341+
is_class_and_exception = obj.type in ["class", "exception"] and obj_parent.type in ["class", "exception"]
342+
if is_same_type_as_parent or is_class_and_exception:
339343
return
340344

341345
obj_child_page_level = _OWN_PAGE_LEVELS.index(obj.type)

autoapi/templates/python/module.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,18 @@ Exceptions
104104
:hidden:
105105

106106
{% for exception in visible_exceptions %}
107+
{#
108+
The set own_page_types sometimes is not ordered! This changes the value of
109+
its last element. Thus, the best way to check is to verify if 'function'
110+
lies within the list
111+
Do -> if 'function' not in own_page_types
112+
Instead of -> if "class" == (own_page_types | list | last)
113+
#}
114+
{% if "method" not in own_page_types %}
115+
{{ exception.short_name }}.rst
116+
{% else %}
107117
{{ exception.short_name }}/index.rst
118+
{% endif %}
108119
{% endfor %}
109120

110121
{% endif %}

0 commit comments

Comments
 (0)