Dspy.SignatureMeta (DSPex v0.11.0)

Copy Markdown View Source

Wrapper for Python class SignatureMeta.

Summary

Functions

Clear the caches (for debugging or testing).

Clear the registry (for debugging or testing).

Python method SignatureMeta._collect_bases_data.

Detect custom types from the caller's frame based on the signature string.

Debug helper to print the ABC registry.

Python method SignatureMeta._get_fields_with_type.

Python method SignatureMeta._validate_fields.

Return a type's method resolution order.

Initialize self. See help(type(self)) for accurate signature.

Register a virtual subclass of an ABC.

Types

t()

@opaque t()

Functions

_abc_caches_clear(ref, opts \\ [])

@spec _abc_caches_clear(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Clear the caches (for debugging or testing).

Returns

  • term()

_abc_registry_clear(ref, opts \\ [])

@spec _abc_registry_clear(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Clear the registry (for debugging or testing).

Returns

  • term()

_collect_bases_data(ref, bases, opts \\ [])

@spec _collect_bases_data(SnakeBridge.Ref.t(), term(), keyword()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Python method SignatureMeta._collect_bases_data.

Parameters

  • bases (term())

Returns

  • term()

_detect_custom_types_from_caller(ref, signature_str, opts \\ [])

@spec _detect_custom_types_from_caller(SnakeBridge.Ref.t(), term(), keyword()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Detect custom types from the caller's frame based on the signature string.

Note: This method relies on Python's frame introspection which has some limitations:

  1. May not work in all Python implementations (e.g., compiled with optimizations)
  2. Looks up a limited number of frames in the call stack
  3. Cannot find types that are imported but not in the caller's namespace

For more reliable custom type resolution, explicitly provide types using the custom_types parameter when creating a Signature.

Parameters

  • signature_str (term())

Returns

  • term()

_dump_registry(ref, args, opts \\ [])

@spec _dump_registry(SnakeBridge.Ref.t(), [term()], keyword()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Debug helper to print the ABC registry.

Parameters

  • file (term() default: None)

Returns

  • term()

_get_fields_with_type(ref, field_type, opts \\ [])

@spec _get_fields_with_type(SnakeBridge.Ref.t(), term(), keyword()) ::
  {:ok, %{optional(String.t()) => term()}} | {:error, Snakepit.Error.t()}

Python method SignatureMeta._get_fields_with_type.

Parameters

  • field_type (term())

Returns

  • %{optional(String.t()) => term()}

_validate_fields(ref, opts \\ [])

@spec _validate_fields(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Python method SignatureMeta._validate_fields.

Returns

  • term()

fields(ref)

@spec fields(SnakeBridge.Ref.t()) :: {:ok, term()} | {:error, Snakepit.Error.t()}

input_fields(ref)

@spec input_fields(SnakeBridge.Ref.t()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

instructions(ref)

@spec instructions(SnakeBridge.Ref.t()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

mro(ref, opts \\ [])

@spec mro(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Return a type's method resolution order.

Returns

  • term()

new(args, opts \\ [])

@spec new(
  [term()],
  keyword()
) :: {:ok, SnakeBridge.Ref.t()} | {:error, Snakepit.Error.t()}

Initialize self. See help(type(self)) for accurate signature.

Parameters

  • args (term())
  • kwargs (term())

output_fields(ref)

@spec output_fields(SnakeBridge.Ref.t()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

register(ref, subclass, opts \\ [])

@spec register(SnakeBridge.Ref.t(), term(), keyword()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

Parameters

  • subclass (term())

Returns

  • term()

signature(ref)

@spec signature(SnakeBridge.Ref.t()) :: {:ok, term()} | {:error, Snakepit.Error.t()}