eradiate._mode.SubtypeDispatcher#

class eradiate._mode.SubtypeDispatcher(type_name, registry=NOTHING)[source]#

Bases: object

This is a very simple factory intended to map mode-specific flags to mode-dependent subtypes. Types can be registered with the register() method, and the appropriate subtype can be resolved with the resolve() method.

register(mode_flags)[source]#

Register a subtype against a combination of mode flags. This method is meant to be used as a decorator.

Parameters:

mode_flags (ModeFlag or str) – Mode flags against which the subtype is registered. If a string is passed, it is converted to a ModeFlag.

resolve(mode_flags=None)[source]#

Resolve the subtype based against a set of mode flags.

Parameters:

mode_flags (ModeFlag, optional) – A mode flag combination used to search the dispatcher’s registry. The first entry that validates the flag conditions is returned, meaning that conflicting or redundant conditions will cause issues. If unspecified, the flags of the currently active mode are used.

See also

Mode.flags, ModeFlag