Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFC Use singular kind strings #137

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sphinx_js/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Attribute(TopLevel, _Member):

#: The type this property's value can have
type: Type
kind: str = "attributes"
kind: Literal["attribute"] = "attribute"


@define
Expand All @@ -285,7 +285,7 @@ class Function(TopLevel, _Member):
exceptions: list[Exc]
returns: list[Return]
type_params: list[TypeParam] = Factory(list)
kind: str = "functions"
kind: Literal["function"] = "function"


@define
Expand All @@ -307,7 +307,7 @@ class Interface(TopLevel, _MembersAndSupers):
"""An interface, a la TypeScript"""

type_params: list[TypeParam] = Factory(list)
kind: str = "interfaces"
kind: Literal["interface"] = "interface"


@define
Expand All @@ -324,7 +324,7 @@ class Class(TopLevel, _MembersAndSupers):
# `undocumented: True` doclet and so are presently filtered out. But we do
# have the space to include them someday.
type_params: list[TypeParam] = Factory(list)
kind: str = "classes"
kind: Literal["class"] = "class"


TopLevelUnion = Class | Interface | Function | Attribute
Expand Down
12 changes: 6 additions & 6 deletions sphinx_js/js/convertTopLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class Converter {
const result: Attribute = {
...this.memberProps(v),
...this.topLevelProperties(v),
kind: "attributes",
kind: "attribute",
type,
};
return [result, v.children];
Expand Down Expand Up @@ -506,7 +506,7 @@ export class Converter {
interfaces: this.relatedTypes(cls, "implementedTypes"),
type_params: this.typeParamsToIR(cls.typeParameters),
...this.topLevelProperties(cls),
kind: "classes",
kind: "class",
};
return [result, cls.children];
}
Expand All @@ -518,7 +518,7 @@ export class Converter {
supers: this.relatedTypes(cls, "extendedTypes"),
type_params: this.typeParamsToIR(cls.typeParameters),
...this.topLevelProperties(cls),
kind: "interfaces",
kind: "interface",
};
return [result, cls.children];
}
Expand Down Expand Up @@ -548,7 +548,7 @@ export class Converter {
...this.memberProps(prop),
...this.topLevelProperties(prop),
description: renderCommentSummary(prop.comment),
kind: "attributes",
kind: "attribute",
};
return [result, prop.children];
}
Expand Down Expand Up @@ -586,7 +586,7 @@ export class Converter {
type: this.renderType(type),
...this.memberProps(prop),
...this.topLevelProperties(prop),
kind: "attributes",
kind: "attribute",
};
result.description = renderCommentSummary(sig.comment);
return [result, prop.children];
Expand Down Expand Up @@ -854,7 +854,7 @@ export class Converter {
type_params,
returns,
exceptions: [],
kind: "functions",
kind: "function",
};
}
typeParamsToIR(
Expand Down
8 changes: 4 additions & 4 deletions sphinx_js/js/ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type TopLevel = {
export type Attribute = TopLevel &
Member & {
type: Type;
kind: "attributes";
kind: "attribute";
};

export type IRFunction = TopLevel &
Expand All @@ -122,7 +122,7 @@ export type IRFunction = TopLevel &
params: Param[];
returns: Return[];
type_params: TypeParam[];
kind: "functions";
kind: "function";
exceptions: never[];
};

Expand All @@ -134,7 +134,7 @@ export type _MembersAndSupers = {
export type Interface = TopLevel &
_MembersAndSupers & {
type_params: TypeParam[];
kind: "interfaces";
kind: "interface";
};

export type Class = TopLevel &
Expand All @@ -143,7 +143,7 @@ export type Class = TopLevel &
is_abstract: boolean;
interfaces: Type[];
type_params: TypeParam[];
kind: "classes";
kind: "class";
};

export type TopLevelIR = Attribute | IRFunction | Class | Interface;
8 changes: 7 additions & 1 deletion sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def _create_modules(self, ir_objects: Sequence[ir.TopLevel]) -> Iterable[ir.Modu
summary section. Skip docs labeled as "@private".
"""
modules = {}
singular_kind_to_plural_kind = {
"class": "classes",
"interface": "interfaces",
"function": "functions",
"attribute": "attributes",
}
for obj, path, kind in self._get_toplevel_objects(ir_objects):
pathparts = path.split("/")
for i in range(len(pathparts) - 1):
Expand All @@ -163,7 +169,7 @@ def _create_modules(self, ir_objects: Sequence[ir.TopLevel]) -> Iterable[ir.Modu
filename=path, deppath=path, path=ir.Pathname(pathparts), line=1
)
mod = modules[path]
getattr(mod, kind).append(obj)
getattr(mod, singular_kind_to_plural_kind[kind]).append(obj)

for mod in modules.values():
mod.attributes = sorted(mod.attributes, key=attrgetter("name"))
Expand Down
Loading