docs: API Reference builder bug fix (#17890)

Issue in the API Reference:
If the `Classes` of `Functions` section is empty, it still shown in API
Reference. Here is an
[example](https://api.python.langchain.com/en/latest/core_api_reference.html#module-langchain_core.agents)
where `Functions` table is empty but still presented.
It happens only if this section has only the "private" members (with
names started with '_'). Those members are not shown but the whole
member section (empty) is shown.
This commit is contained in:
Leonid Ganeline 2024-02-21 12:59:35 -08:00 committed by GitHub
parent 8381f859b4
commit 6f5b7b55bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -217,8 +217,8 @@ def _construct_doc(
for module in namespaces: for module in namespaces:
_members = members_by_namespace[module] _members = members_by_namespace[module]
classes = _members["classes_"] classes = [el for el in _members["classes_"] if el["is_public"]]
functions = _members["functions"] functions = [el for el in _members["functions"] if el["is_public"]]
if not (classes or functions): if not (classes or functions):
continue continue
section = f":mod:`{package_namespace}.{module}`" section = f":mod:`{package_namespace}.{module}`"
@ -244,9 +244,6 @@ Classes
""" """
for class_ in sorted(classes, key=lambda c: c["qualified_name"]): for class_ in sorted(classes, key=lambda c: c["qualified_name"]):
if not class_["is_public"]:
continue
if class_["kind"] == "TypedDict": if class_["kind"] == "TypedDict":
template = "typeddict.rst" template = "typeddict.rst"
elif class_["kind"] == "enum": elif class_["kind"] == "enum":
@ -264,7 +261,7 @@ Classes
""" """
if functions: if functions:
_functions = [f["qualified_name"] for f in functions if f["is_public"]] _functions = [f["qualified_name"] for f in functions]
fstring = "\n ".join(sorted(_functions)) fstring = "\n ".join(sorted(_functions))
full_doc += f"""\ full_doc += f"""\
Functions Functions