Skip to content

Commit

Permalink
Add support for predicate types (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane authored Sep 26, 2023
1 parent e474b2c commit 560f64f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,17 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]
yield self.name


class PredicateType(TypeBase):
type: Literal["predicate"]
name: str
targetType: "TypeD"

def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]:
yield self.name
yield " is "
yield from self.targetType.render_name(converter)


AnyNode = Node | Project | Signature


Expand All @@ -1086,6 +1097,7 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]
| ReferenceType
| ReflectionType
| TupleType
| PredicateType
| UnknownType
)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ export class Iterable {
yield 3;
}
}

export function predicate(c): c is ConstructorlessClass {
return false;
}
1 change: 1 addition & 0 deletions tests/test_build_ts/source/docs/predicate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. js:autofunction:: predicate
16 changes: 16 additions & 0 deletions tests/test_build_ts/test_build_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ class Iterable()
),
)

def test_predicate(self):
self._file_contents_eq(
"predicate",
dedent(
"""\
predicate(c)
Arguments:
* **c** (*any*) --
Returns:
c is "ConstructorlessClass()"
"""
),
)


class TestHtmlBuilder(SphinxBuildTestCase):
"""Tests which require an HTML build of our Sphinx tree, for checking
Expand Down

0 comments on commit 560f64f

Please sign in to comment.