partis.schema_meta.prim module#
- PassValued(val=None, schema=None, loc=None)[source]#
Dummy function that simply returns the original un-modified value
Note
This technically not related to the ‘Valued’ classes, but provides for the ability to ‘pass-through’ a value using a similar call signature as the ‘Valued’ classes.
- class SchemaRef(name, bases, namespace, **kwargs)[source]#
Bases:
ABCMetaBase class of all schema-like class types (is or uses a schema)
- subclass(name=None, module=None, module_set=None, **kwargs)[source]#
Generator function for sub-classing the schema class
- Parameters:
name¶ (NoneType | str) – Name of subclass. If None, will generate a name automatically.
module¶ (None | str | ModuleType) – Module to use for the subclass. If None, the module will be determined from the caller frame. If a string, the module must be importable.
module_set¶ (None | bool) – If True (or None), adds the subclass to the module module. If False, the return value will be the only reference to the subclass.
**kwargs¶ – Keyword arguments passed to __new__ and __init__ of
SchemaMeta.
- Returns:
subclass (
SchemaMeta) – New subclass with the current class as the only base class.
- class SchemaProxy(name, bases, namespace, schema)[source]#
Bases:
SchemaRefBase class for types that use a schema, by is not itself a schema
- Parameters:
- class SchemaDep(name, bases, namespace, schema_deps=None, schema_refs=None)[source]#
Bases:
SchemaRefBase class of concrete schema types
- Parameters:
- schema_depends(schema)[source]#
Reference another schema having this schema as a dependency
- Parameters:
schema¶ (
SchemaDep <partis.schema_meta.schema.SchemaDep) –
- schema_resolved(schema=None)[source]#
Schema previously referenced as a dependency has been resolved
- Parameters:
schema¶ (
SchemaRef <partis.schema_meta.schema.SchemaRef) –
- schema_resolvable(checking=None)[source]#
Schema previously referenced as a dependency has been resolved
- Parameters:
schema¶ (
SchemaRef <partis.schema_meta.schema.SchemaRef) –
- schema_hash_node#
urlsafe Base64 encoded hash of this schema, not including connections (dependencies) to other schemas.
Note
The hash might not include all state information of the object, such as documentation or other data that might be used for informing user interfaces. The intention is the hash only identifies unique data structure.
- Returns:
str
- _schema_hash(visited=None)[source]#
Internal method to format all connections that contribute to the hash of the schema.
The algorithm is generalized to handle reference cycles by enumerating all recursively referenced schemas in a depth-first order with no repeats. Each line is formatted as:
[node index], [hash of node], [list of child node indices]
For example, a hash starting at an arbitrary node marked as
node(0)that includes a dependency cycle:0------<------ | | --<--->-- | | | | 1 3 | | | | 2 --<--->-- | | | | 4 5-->--
2, hash(node(2)), [] 1, hash(node(1)), [2] 4, hash(node(4)), [] 5, hash(node(5)), [0] 3, hash(node(3)), [4, 5] 0, hash(node(0)), [1, 3]
- Parameters:
visited¶ (None | list[
SchemaRef <partis.schema_meta.schema.SchemaRef]) –Internally tracks the schema classes that have already been visited in a depth-first search
Note
This list will be updated by the method call with all nodes visited that where not initially in the list.
- Returns:
list[str]
See also
Note
The hash is only of the relative sub-graph starting at the schema the method is initially called on, and not necessarily of the entire graph of all schemas.
Note
The schema_hash attribute should be used to access the generated hash.
- meta public:
- schema_hash#
urlsafe Base64 encoded hash of this schema, including connections to other schemas.
The
schema_hashis computed to be unique to the combination of all ‘relevent’ attributes and relative connections between this schema and all other referenced schemas. The algorithm is generalized to handle reference cycles by enumerating all recursively referenced schemas in a depth-first order.- Returns:
str
- class SchemaDeclared(name, bases, namespace, schema_deps=None, schema_refs=None)[source]#
Bases:
SchemaDepBase class for all schema forward declarations
A schema declared acts as a forward declaration of a schema class, where a reference to the schema is needed before the schema class has actually been defined. A declared may only be defined by a single eventual schema class.
- schema_resolvable(checking=None)[source]#
Schema previously referenced as a dependency has been resolved
- Parameters:
schema¶ (
SchemaRef <partis.schema_meta.schema.SchemaRef) –
- schema_declared(schema)[source]#
Defines the schema for this schema declared.
Note
This method should return the concrete schema, for example if the provided is a reference to the actual schema to be used to define it, since the declared must act as the reference to the concrete schema and not another reference.
- Parameters:
schema¶ (
SchemaRef <partis.schema_meta.schema.SchemaRef) –- Returns:
SchemaDep <partis.schema_meta.schema.SchemaDep
- class Schema(name, bases, namespace, evaluated=None, default_val=None, default_eval=None, init_val=None, preset_vals=None, schema_deps=None, schema_refs=None, valued_type=None, doc=None, loc=None)[source]#
Bases:
SchemaDepBase class for all schemas
- Parameters:
evaluated¶ (None |
Evaluated) – Class capable to transforming raw source data (such as Python expressions) into the appropriate data type. The val is checked using evaluated.check. If it cannot be interpreted as an expression, the value is validated as is. If not specified, then source data will not be considered as an expression.default_val¶ (None |
OptionalType|RequiredType|DerivedType| object) – The default val (value) of this schema in the case of missing source data. A default of None (or OptionalType) means the value is optional and will be None if source data is missing. A default ofRequiredTypemeans the value is required in the source data and will raise aSchemaValidationErrorif value is missing. A default ofDerivedTypewill attempt to construct a default value from the default values of the struct items, but will raise aSchemaDefinitionErrorif any items themselves have required values. Otherwise, items will be validated against the primitve schema.default_eval¶ (
RequiredType| object) – The default value to use if an evaluated expression results in None. The purpose of this value is that the default_val itself may be an expression that could return None, which would reference back to the default_val causing an un-resolvable loop. If that would occur, then this value will be used as the result of the expression instead of the default_val expression. If default_val is anything other than an expression, specifying this will raise an error to ensure a single source of truth for the resulting value.init_val¶ (None | object) – The initial value that is used when creating an editable template for the value. This differs from default_val in that this value is not used to fill in any missing source data. If None, default_val will be used, or a value will be derived from the schema to produce an initial value that will pass validation. However, init_val may specified independently from default_val.
preset_vals¶ (None | list[ :class: PresetValue <partis.schema_meta.base.PresetValue>]) –
schema_deps¶ (None | list[
SchemaRef]) – Other schemas which this schema depends upon to be defined.schema_refs¶ (None | list[
SchemaRef]) – Other schemas which depend on (defined with) this schema.valued_type¶ (None | type) – The type used to instantiate values that have been validated (‘decoded’) by this schema. This may be initially undefined, by the schema will not be defined/resolved until it is set using the
valued_typesetter.loc¶ (None |
Loc) – Location information of source data (E.G. file, line/column number)
- Raises:
SchemaDefinitionError – If the schema definition is not valid
- schema_resolvable(checking=None)[source]#
Schema previously referenced as a dependency has been resolved
- Parameters:
schema¶ (
SchemaRef <partis.schema_meta.schema.SchemaRef) –
- property hints#
Definition hints.
- Type:
list[
SchemaHint]
- property default_eval#
default value used when the default value is itself an expression that returns nothing.
- Type:
- property evaluated#
Evaluation class
- Type:
Evaluated