ast

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ast holds the Python AST data model. Mirrors the asdl-driven node tree from cpython/Parser/Python.asdl plus the helpers in cpython/Python/asdl.c and cpython/Include/internal/pycore_asdl.h.

The asdl source-of-truth is `cpython/Parser/Python.asdl`; the generated node structs live in nodes_gen.go (produced by tools/asdl_go from that .asdl file). This file ports the runtime helpers.

Index

Constants

View Source
const CoFutureAnnotations uint32 = 0x1000000

CoFutureAnnotations is the CO_FUTURE_ANNOTATIONS bit (PEP 563). Mirrors the value used by future.Annotations so the preprocess pass can be told to skip annotation expressions without taking a future-package dependency (which would import this package transitively).

CPython: Include/cpython/code.h CO_FUTURE_ANNOTATIONS

Variables

View Source
var Ellipsis = EllipsisType{}

Ellipsis is the canonical sentinel for `...` as a Constant value.

View Source
var NoPos = Pos{-1, -1, -1, -1}

NoPos is the sentinel CPython spells (_Py_SourceLocation){-1,-1,-1,-1}.

Functions

func IsDocString

func IsDocString(s Stmt) bool

IsDocString reports whether stmt is the bare-string-literal form recognized by _PyAST_GetDocString. Mirrors the C predicate: an ExprStmt whose value is a string-typed Constant.

CPython: Python/ast.c _PyAST_GetDocString

func Unparse

func Unparse(e Expr) (string, error)

Unparse renders an expression back to source text. Mirrors the limited unparser in cpython/Python/ast_unparse.c which CPython uses to stringize PEP 563/649 annotations during compilation.

CPython: Python/ast_unparse.c expr_as_unicode

func Validate

func Validate(mod Mod) error

Validate is the gopy port of _PyAST_Validate. It walks mod and returns nil if the tree is well-formed, or an error matching CPython's ValueError/TypeError text.

This is the foundation pass: covers Module/Interactive/Expression/ FunctionType plus the node kinds emitted by future and other early pipeline stages (ImportFrom, ExprStmt, Constant). The full validator grows as the asdl-generated nodes land in nodes_gen.go.

CPython: Python/ast.c:L1047 _PyAST_Validate

Types

type Alias

type Alias struct {
	Name   string
	Asname *string
	Pos    Pos
}

Alias is the asdl `alias` node.

func (*Alias) Position

func (n *Alias) Position() Pos

Position returns the source location.

type AnnAssign

type AnnAssign struct {
	Target     Expr
	Annotation Expr
	Value      Expr
	Simple     int
	Pos        Pos
}

AnnAssign is the asdl `AnnAssign` node.

func (*AnnAssign) Position

func (n *AnnAssign) Position() Pos

Position returns the source location.

type Arg

type Arg struct {
	Arg         string
	Annotation  Expr
	TypeComment *string
	Pos         Pos
}

Arg is the asdl `arg` node.

func (*Arg) Position

func (n *Arg) Position() Pos

Position returns the source location.

type Arguments

type Arguments struct {
	Posonlyargs Seq[*Arg]
	Args        Seq[*Arg]
	Vararg      *Arg
	Kwonlyargs  Seq[*Arg]
	KwDefaults  Seq[Expr]
	Kwarg       *Arg
	Defaults    Seq[Expr]
}

Arguments is the asdl `arguments` node.

type Assert

type Assert struct {
	Test Expr
	Msg  Expr
	Pos  Pos
}

Assert is the asdl `Assert` node.

func (*Assert) Position

func (n *Assert) Position() Pos

Position returns the source location.

type Assign

type Assign struct {
	Targets     Seq[Expr]
	Value       Expr
	TypeComment *string
	Pos         Pos
}

Assign is the asdl `Assign` node.

func (*Assign) Position

func (n *Assign) Position() Pos

Position returns the source location.

type AsyncFor

type AsyncFor struct {
	Target      Expr
	Iter        Expr
	Body        Seq[Stmt]
	Orelse      Seq[Stmt]
	TypeComment *string
	Pos         Pos
}

AsyncFor is the asdl `AsyncFor` node.

func (*AsyncFor) Position

func (n *AsyncFor) Position() Pos

Position returns the source location.

type AsyncFunctionDef

type AsyncFunctionDef struct {
	Name          string
	Args          *Arguments
	Body          Seq[Stmt]
	DecoratorList Seq[Expr]
	Returns       Expr
	TypeComment   *string
	TypeParams    Seq[TypeParam]
	Pos           Pos
}

AsyncFunctionDef is the asdl `AsyncFunctionDef` node.

func (*AsyncFunctionDef) Position

func (n *AsyncFunctionDef) Position() Pos

Position returns the source location.

type AsyncWith

type AsyncWith struct {
	Items       Seq[*Withitem]
	Body        Seq[Stmt]
	TypeComment *string
	Pos         Pos
}

AsyncWith is the asdl `AsyncWith` node.

func (*AsyncWith) Position

func (n *AsyncWith) Position() Pos

Position returns the source location.

type Attribute

type Attribute struct {
	Value Expr
	Attr  string
	Ctx   ExprContext
	Pos   Pos
}

Attribute is the asdl `Attribute` node.

func (*Attribute) Position

func (n *Attribute) Position() Pos

Position returns the source location.

type AugAssign

type AugAssign struct {
	Target Expr
	Op     Operator
	Value  Expr
	Pos    Pos
}

AugAssign is the asdl `AugAssign` node.

func (*AugAssign) Position

func (n *AugAssign) Position() Pos

Position returns the source location.

type Await

type Await struct {
	Value Expr
	Pos   Pos
}

Await is the asdl `Await` node.

func (*Await) Position

func (n *Await) Position() Pos

Position returns the source location.

type BinOp

type BinOp struct {
	Left  Expr
	Op    Operator
	Right Expr
	Pos   Pos
}

BinOp is the asdl `BinOp` node.

func (*BinOp) Position

func (n *BinOp) Position() Pos

Position returns the source location.

type BoolOp

type BoolOp struct {
	Op     Boolop
	Values Seq[Expr]
	Pos    Pos
}

BoolOp is the asdl `BoolOp` node.

func (*BoolOp) Position

func (n *BoolOp) Position() Pos

Position returns the source location.

type Boolop

type Boolop int

Boolop is the asdl `boolop` enum.

const (
	And Boolop = iota + 1
	Or
)

func (Boolop) String

func (v Boolop) String() string

String returns the asdl name.

type Break

type Break struct {
	Pos Pos
}

Break is the asdl `Break` node.

func (*Break) Position

func (n *Break) Position() Pos

Position returns the source location.

type Call

type Call struct {
	Func     Expr
	Args     Seq[Expr]
	Keywords Seq[*Keyword]
	Pos      Pos
}

Call is the asdl `Call` node.

func (*Call) Position

func (n *Call) Position() Pos

Position returns the source location.

type ClassDef

type ClassDef struct {
	Name          string
	Bases         Seq[Expr]
	Keywords      Seq[*Keyword]
	Body          Seq[Stmt]
	DecoratorList Seq[Expr]
	TypeParams    Seq[TypeParam]
	Pos           Pos
}

ClassDef is the asdl `ClassDef` node.

func (*ClassDef) Position

func (n *ClassDef) Position() Pos

Position returns the source location.

type Cmpop

type Cmpop int

Cmpop is the asdl `cmpop` enum.

const (
	Eq Cmpop = iota + 1
	NotEq
	Lt
	LtE
	Gt
	GtE
	Is
	IsNot
	In
	NotIn
)

func (Cmpop) String

func (v Cmpop) String() string

String returns the asdl name.

type Compare

type Compare struct {
	Left        Expr
	Ops         Seq[Cmpop]
	Comparators Seq[Expr]
	Pos         Pos
}

Compare is the asdl `Compare` node.

func (*Compare) Position

func (n *Compare) Position() Pos

Position returns the source location.

type Comprehension

type Comprehension struct {
	Target  Expr
	Iter    Expr
	Ifs     Seq[Expr]
	IsAsync int
}

Comprehension is the asdl `comprehension` node.

type Constant

type Constant struct {
	Value any
	Kind  *string
	Pos   Pos
}

Constant is the asdl `Constant` node.

func (*Constant) Position

func (n *Constant) Position() Pos

Position returns the source location.

type Continue

type Continue struct {
	Pos Pos
}

Continue is the asdl `Continue` node.

func (*Continue) Position

func (n *Continue) Position() Pos

Position returns the source location.

type Delete

type Delete struct {
	Targets Seq[Expr]
	Pos     Pos
}

Delete is the asdl `Delete` node.

func (*Delete) Position

func (n *Delete) Position() Pos

Position returns the source location.

type Dict

type Dict struct {
	Keys   Seq[Expr]
	Values Seq[Expr]
	Pos    Pos
}

Dict is the asdl `Dict` node.

func (*Dict) Position

func (n *Dict) Position() Pos

Position returns the source location.

type DictComp

type DictComp struct {
	Key        Expr
	Value      Expr
	Generators Seq[*Comprehension]
	Pos        Pos
}

DictComp is the asdl `DictComp` node.

func (*DictComp) Position

func (n *DictComp) Position() Pos

Position returns the source location.

type EllipsisType

type EllipsisType struct{}

EllipsisType is the singleton type used to spell Python's `...` as a Constant value. CPython uses the dedicated Py_Ellipsis singleton.

type ExceptHandler

type ExceptHandler struct {
	Type Expr
	Name *string
	Body Seq[Stmt]
	Pos  Pos
}

ExceptHandler is the asdl `ExceptHandler` node.

func (*ExceptHandler) Position

func (n *ExceptHandler) Position() Pos

Position returns the source location.

type Excepthandler

type Excepthandler interface {
	Position() Pos
	// contains filtered or unexported methods
}

Excepthandler is the asdl `excepthandler` sum.

type Expr

type Expr interface {
	Position() Pos
	// contains filtered or unexported methods
}

Expr is the asdl `expr` sum.

type ExprContext

type ExprContext int

ExprContext is the asdl `expr_context` enum.

const (
	Load ExprContext = iota + 1
	Store
	Del
)

func (ExprContext) String

func (v ExprContext) String() string

String returns the asdl name.

type ExprStmt

type ExprStmt struct {
	Value Expr
	Pos   Pos
}

ExprStmt is the asdl `ExprStmt` node.

func (*ExprStmt) Position

func (n *ExprStmt) Position() Pos

Position returns the source location.

type Expression

type Expression struct {
	Body Expr
}

Expression is the asdl `Expression` node.

type For

type For struct {
	Target      Expr
	Iter        Expr
	Body        Seq[Stmt]
	Orelse      Seq[Stmt]
	TypeComment *string
	Pos         Pos
}

For is the asdl `For` node.

func (*For) Position

func (n *For) Position() Pos

Position returns the source location.

type FormattedValue

type FormattedValue struct {
	Value      Expr
	Conversion int
	FormatSpec Expr
	Pos        Pos
}

FormattedValue is the asdl `FormattedValue` node.

func (*FormattedValue) Position

func (n *FormattedValue) Position() Pos

Position returns the source location.

type FrozenSet

type FrozenSet []any

FrozenSet wraps a slice of constant items for a frozenset literal. CPython tracks frozenset as a real type; v0.5 only needs a marker so Validate can recurse.

type FunctionDef

type FunctionDef struct {
	Name          string
	Args          *Arguments
	Body          Seq[Stmt]
	DecoratorList Seq[Expr]
	Returns       Expr
	TypeComment   *string
	TypeParams    Seq[TypeParam]
	Pos           Pos
}

FunctionDef is the asdl `FunctionDef` node.

func (*FunctionDef) Position

func (n *FunctionDef) Position() Pos

Position returns the source location.

type FunctionType

type FunctionType struct {
	Argtypes Seq[Expr]
	Returns  Expr
}

FunctionType is the asdl `FunctionType` node.

type GeneratorExp

type GeneratorExp struct {
	Elt        Expr
	Generators Seq[*Comprehension]
	Pos        Pos
}

GeneratorExp is the asdl `GeneratorExp` node.

func (*GeneratorExp) Position

func (n *GeneratorExp) Position() Pos

Position returns the source location.

type Global

type Global struct {
	Names Seq[string]
	Pos   Pos
}

Global is the asdl `Global` node.

func (*Global) Position

func (n *Global) Position() Pos

Position returns the source location.

type If

type If struct {
	Test   Expr
	Body   Seq[Stmt]
	Orelse Seq[Stmt]
	Pos    Pos
}

If is the asdl `If` node.

func (*If) Position

func (n *If) Position() Pos

Position returns the source location.

type IfExp

type IfExp struct {
	Test   Expr
	Body   Expr
	Orelse Expr
	Pos    Pos
}

IfExp is the asdl `IfExp` node.

func (*IfExp) Position

func (n *IfExp) Position() Pos

Position returns the source location.

type Import

type Import struct {
	Names Seq[*Alias]
	Pos   Pos
}

Import is the asdl `Import` node.

func (*Import) Position

func (n *Import) Position() Pos

Position returns the source location.

type ImportFrom

type ImportFrom struct {
	Module *string
	Names  Seq[*Alias]
	Level  *int
	Pos    Pos
}

ImportFrom is the asdl `ImportFrom` node.

func (*ImportFrom) Position

func (n *ImportFrom) Position() Pos

Position returns the source location.

type Interactive

type Interactive struct {
	Body Seq[Stmt]
}

Interactive is the asdl `Interactive` node.

type Interpolation

type Interpolation struct {
	Value      Expr
	Str        any
	Conversion int
	FormatSpec Expr
	Pos        Pos
}

Interpolation is the asdl `Interpolation` node.

func (*Interpolation) Position

func (n *Interpolation) Position() Pos

Position returns the source location.

type JoinedStr

type JoinedStr struct {
	Values Seq[Expr]
	Pos    Pos
}

JoinedStr is the asdl `JoinedStr` node.

func (*JoinedStr) Position

func (n *JoinedStr) Position() Pos

Position returns the source location.

type Keyword

type Keyword struct {
	Arg   *string
	Value Expr
	Pos   Pos
}

Keyword is the asdl `keyword` node.

func (*Keyword) Position

func (n *Keyword) Position() Pos

Position returns the source location.

type Lambda

type Lambda struct {
	Args *Arguments
	Body Expr
	Pos  Pos
}

Lambda is the asdl `Lambda` node.

func (*Lambda) Position

func (n *Lambda) Position() Pos

Position returns the source location.

type List

type List struct {
	Elts Seq[Expr]
	Ctx  ExprContext
	Pos  Pos
}

List is the asdl `List` node.

func (*List) Position

func (n *List) Position() Pos

Position returns the source location.

type ListComp

type ListComp struct {
	Elt        Expr
	Generators Seq[*Comprehension]
	Pos        Pos
}

ListComp is the asdl `ListComp` node.

func (*ListComp) Position

func (n *ListComp) Position() Pos

Position returns the source location.

type Match

type Match struct {
	Subject Expr
	Cases   Seq[*MatchCase]
	Pos     Pos
}

Match is the asdl `Match` node.

func (*Match) Position

func (n *Match) Position() Pos

Position returns the source location.

type MatchAs

type MatchAs struct {
	Pattern Pattern
	Name    *string
	Pos     Pos
}

MatchAs is the asdl `MatchAs` node.

func (*MatchAs) Position

func (n *MatchAs) Position() Pos

Position returns the source location.

type MatchCase

type MatchCase struct {
	Pattern Pattern
	Guard   Expr
	Body    Seq[Stmt]
}

MatchCase is the asdl `match_case` node.

type MatchClass

type MatchClass struct {
	Cls         Expr
	Patterns    Seq[Pattern]
	KwdAttrs    Seq[string]
	KwdPatterns Seq[Pattern]
	Pos         Pos
}

MatchClass is the asdl `MatchClass` node.

func (*MatchClass) Position

func (n *MatchClass) Position() Pos

Position returns the source location.

type MatchMapping

type MatchMapping struct {
	Keys     Seq[Expr]
	Patterns Seq[Pattern]
	Rest     *string
	Pos      Pos
}

MatchMapping is the asdl `MatchMapping` node.

func (*MatchMapping) Position

func (n *MatchMapping) Position() Pos

Position returns the source location.

type MatchOr

type MatchOr struct {
	Patterns Seq[Pattern]
	Pos      Pos
}

MatchOr is the asdl `MatchOr` node.

func (*MatchOr) Position

func (n *MatchOr) Position() Pos

Position returns the source location.

type MatchSequence

type MatchSequence struct {
	Patterns Seq[Pattern]
	Pos      Pos
}

MatchSequence is the asdl `MatchSequence` node.

func (*MatchSequence) Position

func (n *MatchSequence) Position() Pos

Position returns the source location.

type MatchSingleton

type MatchSingleton struct {
	Value any
	Pos   Pos
}

MatchSingleton is the asdl `MatchSingleton` node.

func (*MatchSingleton) Position

func (n *MatchSingleton) Position() Pos

Position returns the source location.

type MatchStar

type MatchStar struct {
	Name *string
	Pos  Pos
}

MatchStar is the asdl `MatchStar` node.

func (*MatchStar) Position

func (n *MatchStar) Position() Pos

Position returns the source location.

type MatchValue

type MatchValue struct {
	Value Expr
	Pos   Pos
}

MatchValue is the asdl `MatchValue` node.

func (*MatchValue) Position

func (n *MatchValue) Position() Pos

Position returns the source location.

type Mod

type Mod interface {
	// contains filtered or unexported methods
}

Mod is the asdl `mod` sum.

type Module

type Module struct {
	Body        Seq[Stmt]
	TypeIgnores Seq[TypeIgnore]
}

Module is the asdl `Module` node.

type Name

type Name struct {
	Id  string
	Ctx ExprContext
	Pos Pos
}

Name is the asdl `Name` node.

func (*Name) Position

func (n *Name) Position() Pos

Position returns the source location.

type NamedExpr

type NamedExpr struct {
	Target Expr
	Value  Expr
	Pos    Pos
}

NamedExpr is the asdl `NamedExpr` node.

func (*NamedExpr) Position

func (n *NamedExpr) Position() Pos

Position returns the source location.

type Nonlocal

type Nonlocal struct {
	Names Seq[string]
	Pos   Pos
}

Nonlocal is the asdl `Nonlocal` node.

func (*Nonlocal) Position

func (n *Nonlocal) Position() Pos

Position returns the source location.

type Operator

type Operator int

Operator is the asdl `operator` enum.

const (
	Add Operator = iota + 1
	Sub
	Mult
	MatMult
	Div
	ModOperator
	Pow
	LShift
	RShift
	BitOr
	BitXor
	BitAnd
	FloorDiv
)

func (Operator) String

func (v Operator) String() string

String returns the asdl name.

type ParamSpec

type ParamSpec struct {
	Name         string
	DefaultValue Expr
	Pos          Pos
}

ParamSpec is the asdl `ParamSpec` node.

func (*ParamSpec) Position

func (n *ParamSpec) Position() Pos

Position returns the source location.

type Pass

type Pass struct {
	Pos Pos
}

Pass is the asdl `Pass` node.

func (*Pass) Position

func (n *Pass) Position() Pos

Position returns the source location.

type Pattern

type Pattern interface {
	Position() Pos
	// contains filtered or unexported methods
}

Pattern is the asdl `pattern` sum.

type Pos

type Pos struct {
	Lineno       int
	ColOffset    int
	EndLineno    int
	EndColOffset int
}

Pos is the source position quadruple. CPython uses _Py_SourceLocation; lineno=-1 marks "no position".

CPython: Include/internal/pycore_location.h _Py_SourceLocation

type PreprocessOptions

type PreprocessOptions struct {
	Filename        string
	OptimizeLevel   int    // -1 default, 0 = no, 1 = -O, 2 = -OO.
	FFFeatures      uint32 // future feature bits (e.g. CO_FUTURE_ANNOTATIONS).
	EnableWarnings  bool   // false under -W ignore.
	SyntaxCheckOnly bool   // true suppresses mutating folds.
}

PreprocessOptions controls which preprocess passes run. Mirrors the _PyASTPreprocessState flag bag.

CPython: Python/ast_preprocess.c _PyASTPreprocessState

type Raise

type Raise struct {
	Exc   Expr
	Cause Expr
	Pos   Pos
}

Raise is the asdl `Raise` node.

func (*Raise) Position

func (n *Raise) Position() Pos

Position returns the source location.

type Return

type Return struct {
	Value Expr
	Pos   Pos
}

Return is the asdl `Return` node.

func (*Return) Position

func (n *Return) Position() Pos

Position returns the source location.

type Seq

type Seq[T any] []T

Seq is the asdl_seq* equivalent. CPython stores sequence length and elements inline in a heap struct allocated from the per-compile arena; in Go a typed slice is the same shape with an O(1) length field (cap/len) and arena-friendly bulk allocation through the underlying slice header.

CPython: Include/internal/pycore_asdl.h:L30 asdl_seq

func NewSeq

func NewSeq[T any](size int) Seq[T]

NewSeq mirrors _Py_asdl_generic_seq_new (and the typed variants _Py_asdl_identifier_seq_new, _Py_asdl_int_seq_new). A zero-length sequence is allocated with an empty slice, not nil, so that Len() is 0 but the sequence itself is non-nil. CPython does the same: _Py_asdl_*_seq_new(0, arena) returns a valid asdl_seq* with size=0.

CPython: Python/asdl.c:L4 GENERATE_ASDL_SEQ_CONSTRUCTOR

func (Seq[T]) Get

func (s Seq[T]) Get(i int) T

Get mirrors asdl_seq_GET. The bounds check matches CPython's debug-build check; release CPython elides it but a panic on Go slice access is the equivalent guarantee.

CPython: Include/internal/pycore_asdl.h:L82 asdl_seq_GET

func (Seq[T]) Len

func (s Seq[T]) Len() int

Len mirrors asdl_seq_LEN. Returns 0 for a nil sequence.

CPython: Include/internal/pycore_asdl.h:L83 asdl_seq_LEN

func (Seq[T]) Set

func (s Seq[T]) Set(i int, v T)

Set mirrors asdl_seq_SET.

CPython: Include/internal/pycore_asdl.h:L86 asdl_seq_SET

type Set

type Set struct {
	Elts Seq[Expr]
	Pos  Pos
}

Set is the asdl `Set` node.

func (*Set) Position

func (n *Set) Position() Pos

Position returns the source location.

type SetComp

type SetComp struct {
	Elt        Expr
	Generators Seq[*Comprehension]
	Pos        Pos
}

SetComp is the asdl `SetComp` node.

func (*SetComp) Position

func (n *SetComp) Position() Pos

Position returns the source location.

type Slice

type Slice struct {
	Lower Expr
	Upper Expr
	Step  Expr
	Pos   Pos
}

Slice is the asdl `Slice` node.

func (*Slice) Position

func (n *Slice) Position() Pos

Position returns the source location.

type Starred

type Starred struct {
	Value Expr
	Ctx   ExprContext
	Pos   Pos
}

Starred is the asdl `Starred` node.

func (*Starred) Position

func (n *Starred) Position() Pos

Position returns the source location.

type Stmt

type Stmt interface {
	Position() Pos
	// contains filtered or unexported methods
}

Stmt is the asdl `stmt` sum.

type Subscript

type Subscript struct {
	Value Expr
	Slice Expr
	Ctx   ExprContext
	Pos   Pos
}

Subscript is the asdl `Subscript` node.

func (*Subscript) Position

func (n *Subscript) Position() Pos

Position returns the source location.

type TemplateStr

type TemplateStr struct {
	Values Seq[Expr]
	Pos    Pos
}

TemplateStr is the asdl `TemplateStr` node.

func (*TemplateStr) Position

func (n *TemplateStr) Position() Pos

Position returns the source location.

type Try

type Try struct {
	Body      Seq[Stmt]
	Handlers  Seq[Excepthandler]
	Orelse    Seq[Stmt]
	Finalbody Seq[Stmt]
	Pos       Pos
}

Try is the asdl `Try` node.

func (*Try) Position

func (n *Try) Position() Pos

Position returns the source location.

type TryStar

type TryStar struct {
	Body      Seq[Stmt]
	Handlers  Seq[Excepthandler]
	Orelse    Seq[Stmt]
	Finalbody Seq[Stmt]
	Pos       Pos
}

TryStar is the asdl `TryStar` node.

func (*TryStar) Position

func (n *TryStar) Position() Pos

Position returns the source location.

type Tuple

type Tuple struct {
	Elts Seq[Expr]
	Ctx  ExprContext
	Pos  Pos
}

Tuple is the asdl `Tuple` node.

func (*Tuple) Position

func (n *Tuple) Position() Pos

Position returns the source location.

type TypeAlias

type TypeAlias struct {
	Name       Expr
	TypeParams Seq[TypeParam]
	Value      Expr
	Pos        Pos
}

TypeAlias is the asdl `TypeAlias` node.

func (*TypeAlias) Position

func (n *TypeAlias) Position() Pos

Position returns the source location.

type TypeIgnore

type TypeIgnore interface {
	// contains filtered or unexported methods
}

TypeIgnore is the asdl `type_ignore` sum.

type TypeIgnoreNode

type TypeIgnoreNode struct {
	Lineno int
	Tag    string
}

TypeIgnoreNode is the asdl `TypeIgnoreNode` node.

type TypeParam

type TypeParam interface {
	Position() Pos
	// contains filtered or unexported methods
}

TypeParam is the asdl `type_param` sum.

type TypeVar

type TypeVar struct {
	Name         string
	Bound        Expr
	DefaultValue Expr
	Pos          Pos
}

TypeVar is the asdl `TypeVar` node.

func (*TypeVar) Position

func (n *TypeVar) Position() Pos

Position returns the source location.

type TypeVarTuple

type TypeVarTuple struct {
	Name         string
	DefaultValue Expr
	Pos          Pos
}

TypeVarTuple is the asdl `TypeVarTuple` node.

func (*TypeVarTuple) Position

func (n *TypeVarTuple) Position() Pos

Position returns the source location.

type UnaryOp

type UnaryOp struct {
	Op      Unaryop
	Operand Expr
	Pos     Pos
}

UnaryOp is the asdl `UnaryOp` node.

func (*UnaryOp) Position

func (n *UnaryOp) Position() Pos

Position returns the source location.

type Unaryop

type Unaryop int

Unaryop is the asdl `unaryop` enum.

const (
	Invert Unaryop = iota + 1
	Not
	UAdd
	USub
)

func (Unaryop) String

func (v Unaryop) String() string

String returns the asdl name.

type Warning

type Warning struct {
	Msg      string
	Filename string
	Pos      Pos
}

Warning is a non-fatal preprocess diagnostic. PEP 765 emits one of these for each `return`/`break`/`continue` that escapes a `finally` block. CPython spells them via _PyErr_EmitSyntaxWarning.

CPython: Python/ast_preprocess.c control_flow_in_finally_warning

func Preprocess

func Preprocess(mod Mod, opt PreprocessOptions) []Warning

Preprocess walks mod, emits PEP 765 control-flow-in-finally warnings, and applies the small set of constant folds CPython 3.14 keeps in the AST layer (printf-format folding, `__debug__` substitution, MatchValue numeric folding, docstring removal at -OO).

CPython: Python/ast_preprocess.c _PyAST_Preprocess

func (Warning) Error

func (w Warning) Error() string

Error formats the warning as a SyntaxWarning-style message.

CPython: Python/ast_preprocess.c PyErr_FormatSyntaxWarningObject

type While

type While struct {
	Test   Expr
	Body   Seq[Stmt]
	Orelse Seq[Stmt]
	Pos    Pos
}

While is the asdl `While` node.

func (*While) Position

func (n *While) Position() Pos

Position returns the source location.

type With

type With struct {
	Items       Seq[*Withitem]
	Body        Seq[Stmt]
	TypeComment *string
	Pos         Pos
}

With is the asdl `With` node.

func (*With) Position

func (n *With) Position() Pos

Position returns the source location.

type Withitem

type Withitem struct {
	ContextExpr  Expr
	OptionalVars Expr
}

Withitem is the asdl `withitem` node.

type Yield

type Yield struct {
	Value Expr
	Pos   Pos
}

Yield is the asdl `Yield` node.

func (*Yield) Position

func (n *Yield) Position() Pos

Position returns the source location.

type YieldFrom

type YieldFrom struct {
	Value Expr
	Pos   Pos
}

YieldFrom is the asdl `YieldFrom` node.

func (*YieldFrom) Position

func (n *YieldFrom) Position() Pos

Position returns the source location.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL