pg.typing.Callable

Accessible via pg.typing.Callable.

class Callable(args=None, kw=None, returns=None, default=MISSING_VALUE, transform=None, callable_type=None, is_noneable=False, frozen=False)[source]

Bases: pg.typing.Generic, ValueSpecBase

Value spec for callable.

Examples:

# A required callable object with any args.
pg.typing.Callable()

# An optional callable objects with the first argument as int, and the
# second argument as float. The field has None as its default value.
pg.typing.Callable([pg.typing.Int(), pg.typing.Float()]).noneable()

# An callable object that has its first argument as int, and has keyword
# arguments 'x' (any type), 'y' (a str) and return value as int.
pg.typing.Callable(
    [pg.typing.Int()],
    kw=[
        ('x', pg.typing.Any()),
        ('y', pg.typing.Str())
    ],
    returns=pg.typing.Int())

See also: pg.typing.Functor.

Attributes:

args

Value specs for positional arguments.

forward_refs

Returns forward references used in this spec.

kw

Names and value specs for keyword arguments.

return_value

Value spec for return value.

Methods:

format(*[, markdown])

Format this spec.

is_compatible(other)

Returns if current spec is compatible with the other value spec.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

property args: List[ValueSpec][source]

Value specs for positional arguments.

format(*, markdown=False, **kwargs)[source]

Format this spec.

Return type:

str

property forward_refs: Set[ForwardRef]

Returns forward references used in this spec.

is_compatible(other)[source]

Returns if current spec is compatible with the other value spec.

Return type:

bool

property kw: List[Tuple[str, ValueSpec]][source]

Names and value specs for keyword arguments.

property return_value: ValueSpec | None[source]

Value spec for return value.

to_json(**kwargs)[source]

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:

**kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.