py-ast - v1.16.0
    Preparing search index...

    Function getSourceSegment

    AST inspection and construction utilities.

    • Get source segment from source code using node location info.

      Slices source using the node's lineno/col_offset/end_lineno/ end_col_offset attributes, matching CPython's ast.get_source_segment.

      Parameters

      • source: string

        The original source code the node was parsed from

      • node: ASTNodeUnion

        The AST node whose corresponding source text should be extracted

      • options: { padded?: boolean } = {}
        • Optionalpadded?: boolean

          When true, pad the first line with leading spaces so its column offsets line up with the original source (default: false)

      Returns string | null

      The extracted source text, or null if the node lacks complete location information