Skip to content

Commit 1312b39

Browse files
committed
Rework TraitDocumenter to fix subclass trait support
Look into the subclasses if the trait is not found in the current class.
1 parent f0062d3 commit 1312b39

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

traits/util/trait_documenter.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from importlib import import_module
1717
import inspect
1818
import io
19+
import types
1920
import token
2021
import tokenize
2122
import traceback
@@ -114,14 +115,17 @@ def add_directive_header(self, sig):
114115
115116
"""
116117
ClassLevelDocumenter.add_directive_header(self, sig)
117-
try:
118-
definition = trait_definition(
119-
cls=self.parent,
120-
trait_name=self.object_name,
121-
)
122-
except ValueError:
123-
# Without this, a failure to find the trait definition aborts
124-
# the whole documentation build.
118+
# Look into the class and parent classes:
119+
classes = [self.parent] + list(types.resolve_bases(self.parent.__bases__))
120+
for cls in classes:
121+
try:
122+
definition = trait_definition(
123+
cls=cls, trait_name=self.object_name)
124+
except ValueError:
125+
continue
126+
else:
127+
break
128+
else:
125129
logger.warning(
126130
"No definition for the trait {!r} could be found in "
127131
"class {!r}.".format(self.object_name, self.parent),

0 commit comments

Comments
 (0)