reflect.Package

An isolated runtime-compiled package.

Reference version

Signature

class reflect.Package

An isolated runtime-compiled package.

Source:<builtin>/reflect/reflect.bamlbytes 16094–24322

Fields

_inner

unknown

Static methods

function

_finish

(
packages: map<string, reflect.Package>
) -> reflect.Package throws unknown
function

compile

(
files: map<string, string>,
packages: map<string, reflect.Package> = …
) -> reflect.Package throws unknown

Compiles files into an isolated package, resolving its dependencies against packages.

Parameters

  • files: source text keyed by path, as the package's baml_src.
  • packages: packages the source may depend on, keyed by the alias it imports them under.

Throws

  • reflect.errors.CompilationError if the source does not compile.
  • anything the package's top-level initialization throws, which is why the clause is unknown.
function

current

() -> reflect.Package throws never

The package lexically enclosing this call site.

Instance methods

function

classes

(self) -> map<string, reflect.Class> throws never

Exported class types, keyed by package-local name.

function

diagnostics

(self) -> reflect.Diagnostic[] throws never

Diagnostics produced while compiling this package.

function

enums

(self) -> map<string, reflect.Enum> throws never

Exported enum types, keyed by package-local name.

function

find_class

(self, name: string) -> reflect.Class | null throws never

The exported class called name, or null if the package exports none.

function

find_enum

(self, name: string) -> reflect.Enum | null throws never

The exported enum called name, or null if the package exports none.

function

find_function

<F>(self, name: string) -> F | null throws reflect.errors.CompilationError

Extract an exported function through an ordinary function-type contract, or null if the package exports no function called name.

Throws

  • reflect.errors.CompilationError if the function exists but is not an F, or is an unspecialized generic.
function

find_global

<T>(self, name: string) -> T | null throws reflect.errors.TypeMismatch

The value of the global called name as T, or null if the package has none. With a nullable T, a global holding null also reads as null; use get_global to tell the two apart.

Throws

  • reflect.errors.TypeMismatch if the global's value is not a T.
function

find_interface

(self, name: string) -> reflect.Interface | null throws never

The exported interface called name, or null if the package exports none.

function

functions

(self) -> map<string, reflect.Function> throws never

Exported free-function signatures, keyed by package-local name.

function

get_class

(self, name: string) -> reflect.Class throws reflect.errors.NotFound

The exported class called name. A name the package exports as some other kind of declaration is a miss. find_class returns null instead of throwing.

Throws

  • reflect.errors.NotFound if the package exports no class called name.
function

get_enum

(self, name: string) -> reflect.Enum throws reflect.errors.NotFound

The exported enum called name. A name the package exports as some other kind of declaration is a miss. find_enum returns null instead of throwing.

Throws

  • reflect.errors.NotFound if the package exports no enum called name.
function

get_function

<F>(
self,
name: string

Extract an exported function through an ordinary function-type contract. find_function returns null for a missing name instead of throwing.

A lookup by name has nowhere to put type arguments, so an unspecialized generic function is refused here.

Throws

  • reflect.errors.NotFound if the package exports no function called name.
  • reflect.errors.CompilationError if the function exists but is not an F, or is an unspecialized generic.
function

get_global

<T>(
self,
name: string

The value of the global variable or client declaration called name, as T. find_global returns null for a missing name instead of throwing.

Throws

  • reflect.errors.NotFound if the package has no global called name.
  • reflect.errors.TypeMismatch if the global's value is not a T.
function

get_interface

(self, name: string) -> reflect.Interface throws reflect.errors.NotFound

The exported interface called name. A name the package exports as some other kind of declaration is a miss. find_interface returns null instead of throwing.

Throws

  • reflect.errors.NotFound if the package exports no interface called name.
function

globals

(self) -> map<string, unknown> throws never

Global variables and client declarations, keyed by package-local name, with their current values. Each value is the global itself, shared with every reader: changing its contents is visible everywhere.

function

interfaces

(self) -> map<string, reflect.Interface> throws never

Exported interface types, keyed by package-local name.

function

tests

(self) -> map<string, () -> null throws unknown> throws unknown

Bundled tests as directly invocable zero-argument callables.

function

with_types

(
self,
types: map<string, reflect.TypeView>
) -> reflect.Package throws reflect.errors.CompilationError

A package that exports everything this one does, plus types under the given names, for a later Package.compile to mount: a bare class, enum, interface, or alias declaration is re-exported under its name (the same declaration, so a consumer that mounts both packages sees one type), any other type is declared as an alias, and every declaration a mounted type reaches is exported under its own name. A name this package already exports is refused.

Implementations

reflect.AnyClass for T

Instance methods

function

attributes

(self) -> reflect.Meta throws never

The class declaration's schema metadata, or empty metadata when the runtime type is not a class.

function

find

<T>(self, name: string) -> T | null throws reflect.errors.TypeMismatch

Read the field called name as T, or null if this value's class declares no such field. A present field holding null also reads as null; use has_field or get<T?> to tell the two apart.

Throws

  • reflect.errors.TypeMismatch if the field's value is not a T.
function

find_field

(self, name: string) -> reflect.class.Field | null throws never

A value-bound handle to the field called name, or null if this value's class declares no such field.

function

get

<T>(self, name: string) -> T throws reflect.errors.NotFound | reflect.errors.TypeMismatch

Read the field called name as T. Read a nullable field with a nullable T (get<int?>). find returns null for a missing field instead of throwing.

Throws

  • reflect.errors.NotFound if this value's class declares no field called name.
  • reflect.errors.TypeMismatch if the field's value is not a T.
function

get_field

(self, name: string) -> reflect.class.Field throws reflect.errors.NotFound

A value-bound handle to the field called name. find_field returns null instead of throwing.

Throws

  • reflect.errors.NotFound if this value's class declares no field called name.
function

has_field

(self, name: string) -> bool throws never

Whether this value's runtime class declares a field called name. false when the runtime type is not a class.

function

list_fields

(self) -> reflect.class.Field[] throws never

Reflected fields bound to this value for Field.value<T>().

function

name

(self) -> string throws never

The rendered name of this value's concrete runtime type.

function

type

(self) -> reflect.Type throws never

This value's concrete runtime type.

Source:<builtin>/reflect/reflect.bamlbytes 14431–14461