BasicRegistrationFactory
- class plasmapy.utils.datatype_factory_base.BasicRegistrationFactory(
- default_widget_type=None,
- additional_validation_functions=None,
- registry=None,
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 feature is under development. Breaking changes may occur in the future.
- Parameters:
Notes
A valid validation function must be a
classmethod
of the registered widget and must returnTrue
orFalse
.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,
Register a widget with the factory.
If
validation_function
is not specified, testsWidgetType
for existence of any function in thevalidation_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 aclassmethod
in thevalidation_functions
attribute is used.is_default (
bool
, optional) – SetsWidgetType
to be the default widget.