pg.CustomTyping

Accessible via pg.CustomTyping, pg.typing.CustomTyping.

class CustomTyping[source]

Bases: object

Interface of custom value type.

Instances of subclasses of CustomTyping can be assigned to fields of any ValueSpec, and take over apply via custom_apply method.

As a result, CustomTyping makes the schema system extensible without modifying existing value specs. For example, value generators can extend CustomTyping and be assignable to any fields.

Methods:

custom_apply(path, value_spec, allow_partial)

Custom apply on a value based on its original value spec.

abstract custom_apply(path, value_spec, allow_partial, child_transform=None)[source]

Custom apply on a value based on its original value spec.

Return type:

Tuple[bool, Any]

Parameters:
  • path – KeyPath of current object under its object tree.

  • value_spec – Original value spec for this field.

  • allow_partial – Whether allow partial object to be created.

  • child_transform – Function to transform child node values into their final values. Transform function is called on leaf nodes first, then on their parents, recursively.

Returns:

A tuple (proceed_with_standard_apply, value_to_proceed).

If proceed_with_standard_apply is set to False, value_to_proceed will be used as final value.

Raises:

Error when the value is not compatible with the value spec.