pyrepr

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCII

func ASCII(v any) string

Python ascii() of a value, its repr with every non ASCII code point escaped

func BuiltinExceptionMRO

func BuiltinExceptionMRO(class string) []string

Class names from a builtin exception class through BaseException as type(exc).__mro__ lists them, nil for any other class

func BytesRepr

func BytesRepr(p []byte) string

Python repr of a bytes value

func Equal

func Equal(a, b any) bool

Python equality over the value model with bool, int and float comparing numerically

func EscapeNonASCII

func EscapeNonASCII(s string) string

Escapes non ASCII code points of WTF-8 text as backslash x, u or U sequences

func ExceptionMROFrom

func ExceptionMROFrom(class string, parents map[string]string) []string

Class names from class up its base chain in parents then the builtin chain, an unknown root deriving from Exception

func ExceptionMessage

func ExceptionMessage(err error) string

Python str of the exception, the message without the class prefix the Go text carries

func ExceptionName

func ExceptionName(err error) string

Python class name of err, a leading class prefix in the text naming it and plain errors standing for Exception

func ExceptionRepr

func ExceptionRepr(err error) string

Python repr of the exception, the class name around the repr of its message or empty parentheses

func Float

func Float(f float64) string

float.__repr__, shortest round trip digits in fixed form between 1e-4 and 1e16 and exponent form outside

func Format

func Format(value any, spec string) (string, error)

Python format(value, spec) for str, int, bool, float and objects that only accept an empty spec

func FormatFieldNames

func FormatFieldNames(template string) ([]string, error)

Field names of a str.format template in order like string.Formatter().parse, with its ValueError messages

func FormatMap

func FormatMap(template string, values map[string]any) (string, error)

Python str.format_map over values, with item lookup, conversions, nested specs and doubled braces

func Int

func Int(v any) (*big.Int, bool)

Integer value of any Go integer kind or big.Int, false for bool and non integers

func Is

func Is(a, b any) bool

Python is operator, pointer identity for reference kinds, both nil alike and equality for plain values

func Or

func Or(v, def any) any

Value of the Python expression v or def

func PercentMap

func PercentMap(format string, lookup func(key string) (any, bool)) (string, error)

Python printf style interpolation of a mapping format, the %(key)s form logging formatters render

func Repr

func Repr(v any) string

Python repr of a Go value modelling None, bool, int, float, str, bytes, list, tuple and dict

func Str

func Str(v any) string

Python str() of a Go value, the text itself for str and the repr otherwise

func StrRepr

func StrRepr(s string) string

Python repr of a str with CPython quote choice, escapes and isprintable test on WTF-8 text

func Truthy

func Truthy(v any) bool

Python truth value of a Go value

func TypeName

func TypeName(v any) string

Python type name of a Go value

Types

type Booler

type Booler interface{ PyBool() bool }

Supplies its own Python truth value

type FormatError

type FormatError struct {
	Class string
	Msg   string
}

Python format failure tagged with the Python exception class it raises

func (*FormatError) Error

func (e *FormatError) Error() string

type Mapping

type Mapping interface {
	PyItems() iter.Seq2[any, any]
}

Renders as a Python dict in its own key order

type PercentError

type PercentError struct {
	Class string
	Msg   string
}

Python exception class and message a printf style interpolation raised

func (*PercentError) Error

func (e *PercentError) Error() string

type PyReprer

type PyReprer interface{ PyRepr() string }

Error whose Python class defines its own repr, like urllib's HTTPError

type PyTypeNamed

type PyTypeNamed interface{ PyTypeName() string }

Error declaring the Python exception class it stands for

type Reprer

type Reprer interface{ PyRepr() string }

Supplies its own Python repr text

type Strer

type Strer interface{ PyStr() string }

Supplies its own Python str text

type Tuple

type Tuple []any

Renders as a Python tuple

type TypeNamer

type TypeNamer interface{ PyTypeName() string }

Supplies its own Python type name

Jump to

Keyboard shortcuts

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