Skip to main content

PackageWalker

ClassSource

PackageWalker()

The package iterative walker.

Specifying a package, this walker will go through the package structure, touch each member and nested module, and analyze the docstring as structured texts.

By providing a customized parser, users can determine how to process the extracted information.

Arguments

Initialization function is not specified.

Methods

get_member_type

v_1: Literal[
"module",
"class",
"dataclass",
"enum",
"typeddict",
"protocol",
"function",
"others",
] = PackageWalker.get_member_type(member: Any)

Detect the type (class) of a member.

Requires

NameTypeRequired
Description
memberAnyThe member to be detected.

Returns

NameType
Description
v_1Literal["module", "class", "dataclass", "enum", "typeddict", "protocol", "function", "others"]The detected type code of the object. This value can be "others" when the member type is unknown.

iter_module_members

(
v_1: (
DocModule
| DocClass
| DocDataClass
| DocEnum
| DocTypedDict
| DocTypeAlias
| DocProtocol
| DocFunction
),
v_2: bool,
) in PackageWalker.iter_module_members(module: ModuleType)

Iterate direct members of a module/package.

Note that this method will not deeply iterate the nested members.

Requires

NameTypeRequired
Description
moduleModuleTypeThe module to be iterated.

Yields

NameType
Description
v_1DocModule | DocClass | DocDataClass | DocEnum | DocTypedDict | DocTypeAlias | DocProtocol | DocFunctionThe extracted structured member information.
v_2boolA flag specifying whether the current member is imported/exported alias.

parse_module_member

v_1: (
DocModule
| DocClass
| DocDataClass
| DocEnum
| DocTypedDict
| DocProtocol
| DocFunction
| None
) = PackageWalker.parse_module_member(
value: Any,
value_type: (
Literal[
"module",
"class",
"dataclass",
"enum",
"typeddict",
"protocol",
"function",
"others",
]
| None
),
)

Parse the module member as structured texts.

Requires

NameTypeRequired
Description
valueAnyThe member value to be parsed.
value_typeLiteral["module", "class", "dataclass", "enum", "typeddict", "protocol", "function", "others"] | NoneThe type code of the value. This type code is provided by get_member_type(...) but does not include "typealias". The type aliases are not parsed by this method.

Returns

NameType
Description
v_1DocModule | DocClass | DocDataClass | DocEnum | DocTypedDict | DocProtocol | DocFunction | NoneThe structred information parsed from value. When the value type is unknown, will return None.

walk_package

self.walk_package(root_pkg: str | ModuleType, handler: ParserAbstract)

Walk through a package.

This method will start from the root of a package, iterate nested members, and call the parser for each touched member.

Users can customizing the processing by providing the implementation of handler (the information parser).

Requires

NameTypeRequired
Description
root_pkgstr | ModuleTypeThe name or the module object of a package.
handlerParserAbstractThe parser that will be called on each nested member of the package.