Skip to content

Commit

Permalink
Suppress inherited class members
Browse files Browse the repository at this point in the history
Don't need to duplicate these between the base class and the subclass.
  • Loading branch information
hoodmane committed Sep 28, 2023
1 parent 4674ff4 commit 317b99d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -527,6 +528,7 @@ class Callable(NodeBase):
"Function",
]
signatures: list["Signature"] = []
inheritedFrom: "ReferenceType | None" = None

@property
def comment(self) -> Comment:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -659,6 +663,7 @@ class Member(NodeBase):
"Variable",
]
type: "TypeD"
inheritedFrom: "ReferenceType | None" = None

def to_ir(
self, converter: Converter
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
5 changes: 5 additions & 0 deletions tests/test_build_ts/source/docs/inherited_docs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. js:autoclass:: Base
:members:

.. js:autoclass:: Extension
:members:
28 changes: 28 additions & 0 deletions tests/test_build_ts/test_build_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 317b99d

Please sign in to comment.