Skip to content

Commit

Permalink
feat: Use module.__all__ to simplify generate_api_docs
Browse files Browse the repository at this point in the history
Removes the need for hardcoding restrictions in multiple places
  • Loading branch information
dangotbanned committed Sep 15, 2024
1 parent da9784e commit 1971daa
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions tools/generate_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,17 @@ def toplevel_charts() -> list[str]:


def encoding_wrappers() -> list[str]:
return sorted(iter_objects(alt.channels, restrict_to_subclass=alt.SchemaBase))
return sorted(iter_objects(alt.channels, restrict_to_subclass=alt.SchemaBase)) # type: ignore[attr-defined]


def api_functions() -> list[str]:
# Exclude `typing` functions/SpecialForm(s)
altair_api_functions = [
obj_name
for obj_name in iter_objects(alt.api, restrict_to_type=types.FunctionType) # type: ignore[attr-defined]
if obj_name
not in {
"cast",
"overload",
"NamedTuple",
"TypedDict",
"is_chart_type",
"runtime_checkable",
}
]
return sorted(altair_api_functions)
KEEP = set(alt.api.__all__) - set(alt.typing.__all__) # type: ignore[attr-defined]
return sorted(
name
for name in iter_objects(alt.api, restrict_to_type=types.FunctionType) # type: ignore[attr-defined]
if name in KEEP
)


def api_classes() -> list[str]:
Expand All @@ -139,7 +131,7 @@ def api_classes() -> list[str]:


def type_hints() -> list[str]:
return [s for s in sorted(iter_objects(alt.typing)) if s != "annotations"]
return sorted(s for s in iter_objects(alt.typing) if s in alt.typing.__all__)


def lowlevel_wrappers() -> list[str]:
Expand Down

0 comments on commit 1971daa

Please sign in to comment.