mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 10:55:57 +00:00
Merge pull request #1860 from staciax/feat/fumadocs-python-type-updates
feat: fumadocs-python type update for consistency
This commit is contained in:
@@ -1,2 +1,10 @@
|
||||
from .document_module import parse_class, parse_function, parse_module
|
||||
from .json_encoder import CustomEncoder
|
||||
|
||||
|
||||
__all__ = (
|
||||
"parse_class",
|
||||
"parse_function",
|
||||
"parse_module",
|
||||
"CustomEncoder",
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from importlib.metadata import version
|
||||
|
||||
import griffe
|
||||
|
||||
@@ -3,6 +3,7 @@ import typing as t
|
||||
import griffe
|
||||
from _griffe.encoders import _json_encoder_map
|
||||
|
||||
|
||||
class CustomEncoder(griffe.JSONEncoder):
|
||||
def default(self, obj: t.Any) -> t.Any:
|
||||
"""Return a serializable representation of the given object.
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
|
||||
|
||||
class Module(t.TypedDict):
|
||||
name: str
|
||||
path: str
|
||||
filepath: str
|
||||
description: str | None
|
||||
docstring: Docstring
|
||||
attributes: t.List[Attribute]
|
||||
modules: t.Dict[str, Module]
|
||||
classes: t.Dict[str, Class]
|
||||
functions: t.Dict[str, Function]
|
||||
version: t.Optional[str]
|
||||
attributes: list[Attribute]
|
||||
modules: dict[str, Module]
|
||||
classes: dict[str, Class]
|
||||
functions: dict[str, Function]
|
||||
version: str | None
|
||||
|
||||
|
||||
class Class(t.TypedDict):
|
||||
name: str
|
||||
path: str
|
||||
description: str | None
|
||||
parameters: t.List[Parameter]
|
||||
attributes: t.List[Attribute]
|
||||
parameters: list[Parameter]
|
||||
attributes: list[Attribute]
|
||||
docstring: Docstring
|
||||
functions: t.Dict[str, Function]
|
||||
functions: dict[str, Function]
|
||||
source: str
|
||||
|
||||
|
||||
@@ -30,18 +32,18 @@ class Function(t.TypedDict):
|
||||
path: str
|
||||
signature: str
|
||||
description: str | None
|
||||
parameters: t.List[Parameter]
|
||||
returns: t.Dict[str, str | None]
|
||||
parameters: list[Parameter]
|
||||
returns: dict[str, str | None]
|
||||
docstring: Docstring
|
||||
source: str
|
||||
|
||||
|
||||
class DocstringSection(t.TypedDict):
|
||||
kind: str
|
||||
value: str | t.List[Parameter]
|
||||
value: str | list[Parameter]
|
||||
|
||||
|
||||
Docstring = t.List[DocstringSection]
|
||||
Docstring = list[DocstringSection]
|
||||
|
||||
|
||||
class Parameter(t.TypedDict):
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import typing as t
|
||||
from dataclasses import asdict
|
||||
|
||||
import griffe
|
||||
|
||||
SimplifiedDocstring = t.NamedTuple(
|
||||
"DocComponents",
|
||||
[
|
||||
("description", str),
|
||||
("parameters", list),
|
||||
("returns", dict),
|
||||
("attributes", list),
|
||||
("remainder", list),
|
||||
],
|
||||
)
|
||||
|
||||
class SimplifiedDocstring(t.NamedTuple):
|
||||
description: str | None
|
||||
parameters: list[dict[str, str | None]]
|
||||
returns: dict[str, str | None]
|
||||
attributes: list[dict[str, str | None]]
|
||||
remainder: list[griffe.DocstringSection]
|
||||
|
||||
|
||||
def simplify_docstring(
|
||||
@@ -52,9 +48,7 @@ def simplify_docstring(
|
||||
"value": attr.value,
|
||||
}
|
||||
for attr in parent.attributes.values()
|
||||
if (
|
||||
not attr.is_alias and not attr.is_private
|
||||
)
|
||||
if (not attr.is_alias and not attr.is_private)
|
||||
]
|
||||
|
||||
description = None
|
||||
@@ -150,9 +144,9 @@ def simplify_docstring(
|
||||
{
|
||||
"name": attr.name,
|
||||
"annotation": attr.annotation,
|
||||
"description": attr.docstring.parsed
|
||||
if attr.docstring
|
||||
else None,
|
||||
"description": (
|
||||
attr.docstring.parsed if attr.docstring else None
|
||||
),
|
||||
"value": attr.value,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import typing as t
|
||||
|
||||
import griffe
|
||||
|
||||
|
||||
def build_signature(func: griffe.Function) -> str:
|
||||
parameters: t.List[griffe.Parameter] = func.parameters
|
||||
parameters: list[griffe.Parameter] = func.parameters
|
||||
|
||||
s = "("
|
||||
positional_only = True
|
||||
@@ -41,7 +39,7 @@ def build_signature(func: griffe.Function) -> str:
|
||||
return s
|
||||
|
||||
|
||||
def filter_non_imported(d: t.Dict[str, griffe.Object]) -> dict:
|
||||
def filter_non_imported(d: dict[str, griffe.Object]) -> dict:
|
||||
return {k: v for k, v in d.items() if not v.is_imported}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user