Skip to content

extensions ¤

This module is the public interface to import elements from the base.

Modules:

  • base

    This module contains the base classes for dealing with extensions.

  • dataclasses

    Built-in extension adding support for dataclasses.

  • hybrid

    Deprecated. This extension provides an hybrid behavior while loading data.

Classes:

  • Extension

    Base class for Griffe extensions.

  • Extensions

    This class helps iterating on extensions that should run at different times.

  • InspectorExtension

    Deprecated in favor of Extension. The object inspector extension base class, to inherit from.

  • VisitorExtension

    Deprecated in favor of Extension. The node visitor extension base class, to inherit from.

  • When

    Enumeration of the different times at which an extension is used.

Functions:

Extension ¤

Base class for Griffe extensions.

Methods:

generic_inspect ¤

generic_inspect(node: ObjectNode) -> None

Extend the base generic inspection with extensions.

Parameters:

generic_visit ¤

generic_visit(node: AST) -> None

Visit children nodes.

Parameters:

  • node (AST) –

    The node to visit the children of.

inspect ¤

inspect(node: ObjectNode) -> None

Inspect a node.

Parameters:

on_attribute_instance ¤

on_attribute_instance(
    *, node: AST | ObjectNode, attr: Attribute
) -> None

Run when an Attribute has been created.

Parameters:

on_attribute_node ¤

on_attribute_node(*, node: AST | ObjectNode) -> None

Run when visiting a new attribute node during static/dynamic analysis.

Parameters:

on_class_instance ¤

on_class_instance(
    *, node: AST | ObjectNode, cls: Class
) -> None

Run when a Class has been created.

Parameters:

  • node (AST | ObjectNode) –

    The currently visited node.

  • cls (Class) –

    The class instance.

on_class_members ¤

on_class_members(
    *, node: AST | ObjectNode, cls: Class
) -> None

Run when members of a Class have been loaded.

Parameters:

  • node (AST | ObjectNode) –

    The currently visited node.

  • cls (Class) –

    The class instance.

on_class_node ¤

on_class_node(*, node: AST | ObjectNode) -> None

Run when visiting a new class node during static/dynamic analysis.

Parameters:

on_function_instance ¤

on_function_instance(
    *, node: AST | ObjectNode, func: Function
) -> None

Run when a Function has been created.

Parameters:

on_function_node ¤

on_function_node(*, node: AST | ObjectNode) -> None

Run when visiting a new function node during static/dynamic analysis.

Parameters:

on_instance ¤

on_instance(*, node: AST | ObjectNode, obj: Object) -> None

Run when an Object has been created.

Parameters:

  • node (AST | ObjectNode) –

    The currently visited node.

  • obj (Object) –

    The object instance.

on_members ¤

on_members(*, node: AST | ObjectNode, obj: Object) -> None

Run when members of an Object have been loaded.

Parameters:

  • node (AST | ObjectNode) –

    The currently visited node.

  • obj (Object) –

    The object instance.

on_module_instance ¤

on_module_instance(
    *, node: AST | ObjectNode, mod: Module
) -> None

Run when a Module has been created.

Parameters:

  • node (AST | ObjectNode) –

    The currently visited node.

  • mod (Module) –

    The module instance.

on_module_members ¤

on_module_members(
    *, node: AST | ObjectNode, mod: Module
) -> None

Run when members of a Module have been loaded.

Parameters:

  • node (AST | ObjectNode) –

    The currently visited node.

  • mod (Module) –

    The module instance.

on_module_node ¤

on_module_node(*, node: AST | ObjectNode) -> None

Run when visiting a new module node during static/dynamic analysis.

Parameters:

on_node ¤

on_node(*, node: AST | ObjectNode) -> None

Run when visiting a new node during static/dynamic analysis.

Parameters:

on_package_loaded ¤

on_package_loaded(*, pkg: Module) -> None

Run when a package has been completely loaded.

Parameters:

  • pkg (Module) –

    The package (Module) instance.

visit ¤

visit(node: AST) -> None

Visit a node.

Parameters:

  • node (AST) –

    The node to visit.

Extensions ¤

Extensions(*extensions: ExtensionType)

This class helps iterating on extensions that should run at different times.

Parameters:

  • *extensions (ExtensionType, default: () ) –

    The extensions to add.

Methods:

  • add

    Add extensions to this container.

  • attach_inspector

    Attach a parent inspector to the inspector extensions.

  • attach_visitor

    Attach a parent visitor to the visitor extensions.

  • call

    Call the extension hook for the given event.

Attributes:

after_children_inspection property ¤

after_children_inspection: list[InspectorExtension]

The inspectors that run after the children inspection.

after_children_visit property ¤

after_children_visit: list[VisitorExtension]

The visitors that run after the children visit.

after_inspection property ¤

after_inspection: list[InspectorExtension]

The inspectors that run after the inspection.

after_visit property ¤

after_visit: list[VisitorExtension]

The visitors that run after the visit.

before_children_inspection property ¤

before_children_inspection: list[InspectorExtension]

The inspectors that run before the children inspection.

before_children_visit property ¤

before_children_visit: list[VisitorExtension]

The visitors that run before the children visit.

before_inspection property ¤

before_inspection: list[InspectorExtension]

The inspectors that run before the inspection.

before_visit property ¤

before_visit: list[VisitorExtension]

The visitors that run before the visit.

add ¤

add(*extensions: ExtensionType) -> None

Add extensions to this container.

Parameters:

  • *extensions (ExtensionType, default: () ) –

    The extensions to add.

attach_inspector ¤

attach_inspector(parent_inspector: Inspector) -> Extensions

Attach a parent inspector to the inspector extensions.

Parameters:

  • parent_inspector (Inspector) –

    The parent inspector, leading the inspection.

Returns:

attach_visitor ¤

attach_visitor(parent_visitor: Visitor) -> Extensions

Attach a parent visitor to the visitor extensions.

Parameters:

  • parent_visitor (Visitor) –

    The parent visitor, leading the visit.

Returns:

call ¤

call(event: str, **kwargs: Any) -> None

Call the extension hook for the given event.

Parameters:

  • event (str) –

    The trigerred event.

  • **kwargs (Any, default: {} ) –

    Arguments passed to the hook.

InspectorExtension ¤

InspectorExtension()

Deprecated in favor of Extension. The object inspector extension base class, to inherit from.

Methods:

  • attach

    Attach the parent inspector to this extension.

  • inspect

    Inspect a node.

attach ¤

attach(inspector: Inspector) -> None

Attach the parent inspector to this extension.

Parameters:

  • inspector (Inspector) –

    The parent inspector.

inspect ¤

inspect(node: ObjectNode) -> None

Inspect a node.

Parameters:

VisitorExtension ¤

VisitorExtension()

Deprecated in favor of Extension. The node visitor extension base class, to inherit from.

Methods:

  • attach

    Attach the parent visitor to this extension.

  • visit

    Visit a node.

attach ¤

attach(visitor: Visitor) -> None

Attach the parent visitor to this extension.

Parameters:

  • visitor (Visitor) –

    The parent visitor.

visit ¤

visit(node: AST) -> None

Visit a node.

Parameters:

  • node (AST) –

    The node to visit.

When ¤


          flowchart TD
          griffe.extensions.When[When]

          

          click griffe.extensions.When href "" "griffe.extensions.When"
          

Enumeration of the different times at which an extension is used.

Attributes:

  • after_all (int) –

    For each node, after the visit/inspection.

  • after_children (int) –

    For each node, after the children have been visited/inspected, and before finishing the visit/inspection.

  • before_all (int) –

    For each node, before the visit/inspection.

  • before_children (int) –

    For each node, after the visit has started, and before the children visit/inspection.

after_all class-attribute instance-attribute ¤

after_all: int = 4

For each node, after the visit/inspection.

after_children class-attribute instance-attribute ¤

after_children: int = 3

For each node, after the children have been visited/inspected, and before finishing the visit/inspection.

before_all class-attribute instance-attribute ¤

before_all: int = 1

For each node, before the visit/inspection.

before_children class-attribute instance-attribute ¤

before_children: int = 2

For each node, after the visit has started, and before the children visit/inspection.

load_extensions ¤

load_extensions(
    exts: (
        Sequence[
            str
            | dict[str, Any]
            | ExtensionType
            | type[ExtensionType]
        ]
        | None
    ) = None
) -> Extensions

Load configured extensions.

Parameters:

  • exts (Sequence[str | dict[str, Any] | ExtensionType | type[ExtensionType]] | None, default: None ) –

    A sequence of extension, with potential configuration options.

Returns: