pg.symbolic.augment_schema

Accessible via pg.symbolic.augment_schema.

augment_schema(schema, fields, extend=True, *, init_arg_list=None, metadata=None, description=None)[source]

Gets the augmented schema from class with extra fields and metadata.

Return type:

pg.Schema

Parameters:
  • schema – The original schema.

  • fields – A list of pg.typing.Field or equivalent tuple representation as (<key>, <value-spec>, [description], [metadata-objects]). key should be a string. value-spec should be pg_typing.ValueSpec classes or equivalent, e.g. primitive values which will be converted to ValueSpec implementation according to its type and used as its default value. description is optional only when field overrides a field from its parent class. metadata-objects is an optional list of any type, which can be used to generate code according to the schema.

  • extend – If True, extend existing schema using fields. Otherwise replace existing schema with a new schema created from fields.

  • init_arg_list – An optional sequence of strings as the positional argument list for __init__. This is helpful when symbolic attributes are inherited from base classes or the user want to change its order. If not provided, the init_arg_list will be automatically generated from symbolic attributes defined from pg.members in their declaration order, from the base classes to the subclass.

  • metadata – Optional dict of user objects as class-level metadata which will be attached to class schema.

  • description – An optional description to set.

Returns:

The augmented schema (new copy).