pg.typing.Object

Accessible via pg.typing.Object.

class Object(t, default=MISSING_VALUE, transform=None, is_noneable=False, frozen=False)[source]

Bases: pg.typing.Generic, ValueSpecBase

Value spec for object type.

Examples:

# A required instance of class A and its subclasses.
pg.typing.Object(A)

# A required instance of class A and its subclasses (forward declaration).
pg.typing.Object('A')

# An optional instance of class A with None as its default value.
pg.typing.Object(A).noneable()

# An instance of class A with default value.
pg.typing.Object(A, default=A())

Attributes:

cls

Returns the class of this object spec.

forward_refs

Returns forward references used in this spec.

schema

Returns the schema of object class if available.

value_type

Returns acceptable value type(s) for current value spec.

Methods:

extend(base)

Extend current value spec on top of a base spec.

format([compact, verbose, root_indent, ...])

Format this object.

to_json(**kwargs)

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

property cls: Type[Any][source]

Returns the class of this object spec.

extend(base)[source]

Extend current value spec on top of a base spec.

Return type:

pg.ValueSpec

format(compact=False, verbose=True, root_indent=0, *, markdown=False, hide_default_values=True, hide_missing_values=True, **kwargs)[source]

Format this object.

Return type:

str

property forward_refs: Set[ForwardRef][source]

Returns forward references used in this spec.

property schema: Schema | None[source]

Returns the schema of object class if available.

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.

property value_type: Type[Any][source]

Returns acceptable value type(s) for current value spec.