From 317b99d619c79131d1c85fdbdfeb286ba5ebde71 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 27 Sep 2023 19:30:32 -0700 Subject: [PATCH] Suppress inherited class members Don't need to duplicate these between the base class and the subclass. --- sphinx_js/typedoc.py | 11 ++++---- tests/test_build_ts/source/class.ts | 12 ++++++++ .../source/docs/inherited_docs.rst | 5 ++++ tests/test_build_ts/test_build_ts.py | 28 +++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 tests/test_build_ts/source/docs/inherited_docs.rst diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index b2b14b55..ead8971d 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -479,6 +479,7 @@ class Accessor(NodeBase): kindString: Literal["Accessor"] getSignature: "Signature | None" = None setSignature: "Signature | None" = None + inheritedFrom: "ReferenceType | None" = None @property def comment(self) -> Comment: @@ -527,6 +528,7 @@ class Callable(NodeBase): "Function", ] signatures: list["Signature"] = [] + inheritedFrom: "ReferenceType | None" = None @property def comment(self) -> Comment: @@ -605,6 +607,8 @@ def _constructor_and_members( constructor: ir.Function | None = None members = [] for child in self.children: + if child.inheritedFrom is not None and child.comment == DEFAULT_COMMENT: + continue if child.kindString == "Constructor": # This really, really should happen exactly once per class. # Type parameter cannot appear on constructor declaration so copy @@ -659,6 +663,7 @@ class Member(NodeBase): "Variable", ] type: "TypeD" + inheritedFrom: "ReferenceType | None" = None def to_ir( self, converter: Converter @@ -829,7 +834,7 @@ class Signature(TopLevelProperties): parameters: list["Param"] = [] sources: list[Source] = [] type: "TypeD" # This is the return type! - inheritedFrom: Any = None + inheritedFrom: "ReferenceType | None" = None parent_member_properties: MemberProperties = {} # type: ignore[typeddict-item] def _path_segments(self, base_dir: str) -> list[str]: @@ -944,10 +949,6 @@ def inner(param: Param) -> Iterator[str | ir.TypeXRef]: def to_ir( self, converter: Converter ) -> tuple[ir.Function | None, Sequence["Node"]]: - if self.inheritedFrom is not None: - if self.comment == Comment(): - return None, [] - if self.name.startswith("["): # a symbol. # \u2024 looks like a period but is not a period. diff --git a/tests/test_build_ts/source/class.ts b/tests/test_build_ts/source/class.ts index dfefff04..573ec4e9 100644 --- a/tests/test_build_ts/source/class.ts +++ b/tests/test_build_ts/source/class.ts @@ -137,3 +137,15 @@ export class GetSetDocs { */ set b(x) {} } + +export class Base { + /** Some docs for f */ + f() {} + + get a() { return 7; } +} + +export class Extension extends Base { + /** Some docs for g */ + g() {} +} diff --git a/tests/test_build_ts/source/docs/inherited_docs.rst b/tests/test_build_ts/source/docs/inherited_docs.rst new file mode 100644 index 00000000..80824160 --- /dev/null +++ b/tests/test_build_ts/source/docs/inherited_docs.rst @@ -0,0 +1,5 @@ +.. js:autoclass:: Base + :members: + +.. js:autoclass:: Extension + :members: diff --git a/tests/test_build_ts/test_build_ts.py b/tests/test_build_ts/test_build_ts.py index 1dda481b..a14a7703 100644 --- a/tests/test_build_ts/test_build_ts.py +++ b/tests/test_build_ts/test_build_ts.py @@ -214,6 +214,34 @@ class GetSetDocs() ), ) + def test_inherited_docs(self): + # Check that we aren't including documentation entries from the base class + self._file_contents_eq( + "inherited_docs", + dedent( + """\ + class Base() + + *exported from* "class" + + Base.a + + **type:** number + + Base.f() + + Some docs for f + + class Extension() + + *exported from* "class" + + **Extends:** + * "Base()" + """ + ), + ) + class TestHtmlBuilder(SphinxBuildTestCase): """Tests which require an HTML build of our Sphinx tree, for checking