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

Fix the properties that were incorrectly marked as methods in Qiskit 0.24-0.28 #1387

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion scripts/lib/api/generateApiComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function prepareProps(
// Remove the attributes and properties modifiers as we don't show their signatures,
// but we still use them to create their headers
if (apiType == "attribute" || apiType == "property") {
findByText($, $main, "em.property", apiType).remove();
findByText($, $child, "em.property", apiType).remove();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to restrict the search to the signature node. Before we were searching in the whole DOM which should be slower. Tested regenerating some historical versions (not all of them) as well as qiskit 1.0 and the dev version.

}

if (!(apiType in preparePropsPerApiType)) {
Expand Down
13 changes: 13 additions & 0 deletions scripts/lib/api/processHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ export function updateModuleHeadings(
}

function getApiType($dl: Cheerio<any>): ApiType | undefined {
// Historical versions were generating properties incorrectly as methods.
// We can fix this by looking at the modifier before the signature.
// See https://github.com/Qiskit/documentation/issues/1352 for more information.
if (hasPropertyModifier($dl)) {
return "property";
}

for (const className of [
"function",
"class",
Expand All @@ -390,3 +397,9 @@ function getApiType($dl: Cheerio<any>): ApiType | undefined {

return undefined;
}

function hasPropertyModifier($dl: Cheerio<any>): boolean {
const rawModifiers = $dl.find("dt").find("em.property");
const modifiers = rawModifiers.text().trim();
return modifiers == "property";
}