Class ConstantField

Synopsis

class ConstantField(InterfaceField)

Description

Used to define config-attribute that can't be overriden

Inheritance

Ancestors: InterfaceField

Methods

__init__

Source

Lines 107-122 in anyfig/fields.py.

class ConstantField(InterfaceField):
  ''' Used to define config-attribute that can't be overriden '''
  def __init__(self, value, strict):
    if strict:
      super().__init__(tests=lambda v: v is value)
    else:
      super().__init__(tests=lambda v: v == value)
    self.value = value

  def _check_test(self, test, name, value, config_class):
    ''' Calls the test with the new attribute value. Raises error if test doesn't pass '''
    err_msg = f"Can't override constant '{name}' with value '{value}' in config '{config_class}'"
    assert test(value), err_msg


class InputField(InterfaceField):





Add Discussion as Guest

Log in