def __call__()

in core/src/klio_core/config/_utils.py [0:0]


    def __call__(self, cls):

        known_keys = []
        # add type checking converters to attribs before running through
        # attr.attrs()
        for key, attrib in cls.__dict__.items():
            if hasattr(attrib, "_default") and hasattr(attrib, "converter"):
                if attrib._default == attr.NOTHING:
                    attrib._default = converters.UNSET_REQUIRED_VALUE

                # wrap any validator in one that includes the key in the error
                # message
                if attrib._validator is not None:
                    attrib._validator = WrappedValidator(
                        self._full_key(key), attrib._validator
                    )

                if attrib.type is not None:
                    attrib.converter = converters.Converters.for_type(
                        attrib.type, self._full_key(key)
                    )
                else:
                    attrib.converter = converters.ConfigValueConverter(
                        self._full_key(key)
                    ).validate

                known_keys.append(key)

        # now we can let attrs work its magic
        attrib_cls = attr.attrs(cls)

        # lastly we'll replace the __init__ provided by attrs (which accepts
        # arguments directly) with one that accepts a dict along with
        # additional kargs, merges and cleans it up before passing it to attrs

        original_init = attrib_cls.__init__

        # need to alias self so we don't confuse the decorated class with this
        # decorator class!
        me = self

        def init_from_dict(self, config_dict={}, **extra_kwargs):
            original_init(
                self,
                **me._prepare_config_dict(
                    known_keys, config_dict, **extra_kwargs
                )
            )
            if hasattr(self, "__config_post_init__"):
                self.__config_post_init__(config_dict)

        attrib_cls.__init__ = init_from_dict
        attrib_cls.from_values = original_init
        return attrib_cls