future

package
v0.12.3 Latest Latest
Warning

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

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

Documentation

Overview

Package future ports cpython/Python/future.c. It walks a Module AST past its docstring and collects __future__ imports into a Features bitmask plus the location of the last __future__ statement.

Index

Constants

View Source
const (
	Division        uint32 = 0x20000
	AbsoluteImport  uint32 = 0x40000
	WithStatement   uint32 = 0x80000
	PrintFunction   uint32 = 0x100000
	UnicodeLiterals uint32 = 0x200000
	BarryAsBdfl     uint32 = 0x400000
	GeneratorStop   uint32 = 0x800000
	Annotations     uint32 = 0x1000000
)

CO_FUTURE_* flag bits. Numeric values match cpython/Include/cpython/code.h byte-for-byte so that a code object produced by gopy carries flags interchangeable with CPython.

CPython: Include/cpython/code.h:L135

Variables

This section is empty.

Functions

This section is empty.

Types

type Features

type Features struct {
	Bits     uint32
	Location ast.Pos
}

Features is the gopy equivalent of CPython's _PyFutureFeatures.

CPython: Include/internal/pycore_symtable.h _PyFutureFeatures

func FromAST

func FromAST(mod ast.Mod, filename string) (*Features, error)

FromAST walks mod and returns the collected __future__ feature set. Walks Module and Interactive bodies; any other top-level shape returns a zero Features cleanly. Mirrors _PyFuture_FromAST.

CPython: Python/future.c:L109 _PyFuture_FromAST

type SyntaxError

type SyntaxError struct {
	Msg      string
	Filename string
	Pos      ast.Pos
}

SyntaxError carries the same shape as the Python SyntaxError that CPython raises from this module: a message plus the source range.

CPython: Python/future.c PyErr_RangedSyntaxLocationObject

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Error formats the syntax error as a plain string.

CPython: Python/future.c PyErr_RangedSyntaxLocationObject message

Jump to

Keyboard shortcuts

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