BasicRegistrationFactory

class plasmapy.utils.datatype_factory_base.BasicRegistrationFactory(default_widget_type=None, additional_validation_functions=None, registry=None)[source]

Bases: object

Generalized registrable factory type.

Widgets (classes) can be registered with an instance of this class. Arguments to the factory’s __call__ method are then passed to a function specified by the registered factory, which validates the input and returns a instance of the class that best matches the inputs.

Attention

This functionality is under development. Backward incompatible changes might occur in future releases.

registry

Dictionary mapping classes (key) to function (value) which validates input.

Type:

dict

default_widget_type

Class of the default widget. Defaults to None.

Type:

type

validation_functions

List of function names that are valid validation functions.

Type:

list of str

Parameters:
  • default_widget_type (type, optional) –

  • additional_validation_functions (list of str, optional) – List of strings corresponding to additional validation function names.

Notes

A valid validation function must be a classmethod of the registered widget and must return True or False.

Methods Summary

__call__(*args, **kwargs)

Method for running the factory.

register(WidgetType[, validation_function, ...])

Register a widget with the factory.

unregister(WidgetType)

Remove a widget from the factory's registry.

Methods Documentation

__call__(*args, **kwargs)[source]

Method for running the factory.

Arguments args and kwargs are passed through to the validation function and to the constructor for the final type.

register(WidgetType, validation_function=None, is_default: bool = False)[source]

Register a widget with the factory.

If validation_function is not specified, tests WidgetType for existence of any function in the validation_functions attribute, which is a list of strings which must be callable class attributes.

Parameters:
  • WidgetType (type) – Widget to register.

  • validation_function (function, optional) – Function to validate against. Defaults to None, which indicates that a classmethod in the validation_functions attribute is used.

  • is_default (bool, optional) – Sets WidgetType to be the default widget.

unregister(WidgetType) None[source]

Remove a widget from the factory’s registry.