Repository: Avaiga/taipy
File: taipy/common/config/__init__.py (Python)

Code before:

def _config_doc_for_section(func):
    def func_with_doc(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections=False):
        __write_section_to_doc(section, attribute_name)
        __write_method_to_doc(configuration_methods)
        return func(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections)

    return func_with_doc


def _config_doc_for_method(func):
    def func_with_doc(configuration_methods):
        __write_method_to_doc(configuration_methods)
        return func(configuration_methods)

    return func_with_doc


@_config_doc_for_section
def _inject_section(
    section_clazz,
    attribute_name: str,
    default: Section,
    configuration_methods: List[tuple],
    add_to_unconflicted_sections: bool = False,
):
    from ._serializer._base_serializer import _BaseSerializer

    Config._register_default(default)

    if issubclass(section_clazz, UniqueSection):
        setattr(Config, attribute_name, Config.unique_sections[section_clazz.name])
    elif issubclass(section_clazz, Section):
        setattr(Config, attribute_name, Config.sections[section_clazz.name])
    else:
        raise TypeError

    if add_to_unconflicted_sections:
        Config._comparator._add_unconflicted_section(section_clazz.name)  # type: ignore[attr-defined]

    for exposed_configuration_method, configuration_method in configuration_methods:
        setattr(Config, exposed_configuration_method, configuration_method)

    for type_to_register in section_clazz._types_to_register():
        if type_to_register._type_identifier() not in _BaseSerializer._SERIALIZABLE_TYPES:
            _BaseSerializer._SERIALIZABLE_TYPES.append(type_to_register._type_identifier())


@_config_doc_for_method
def _inject_method(configuration_methods: List[tuple]):
    for exposed_configuration_method, configuration_method in configuration_methods:

Review comment (suggestion):
This import command is inside the method because this is an `__init__.py` file and we don't want to expose the `_BaseSerializer`

Code after:
def _config_doc_for_section(func):  # pragma: no cover
    def func_with_doc(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections=False):
        __write_section_to_doc(section, attribute_name)
        __write_method_to_doc(configuration_methods)
        return func(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections)

    return func_with_doc


def _config_doc_for_method(func):  # pragma: no cover
    def func_with_doc(configuration_methods):
        __write_method_to_doc(configuration_methods)
        return func(configuration_methods)

    return func_with_doc


@_config_doc_for_section
def _inject_section(
    section_clazz,
    attribute_name: str,
    default: Section,
    configuration_methods: List[tuple],
    add_to_unconflicted_sections: bool = False,
):
    from ._serializer._base_serializer import _BaseSerializer

    Config._register_default(default)

    if issubclass(section_clazz, UniqueSection):
        setattr(Config, attribute_name, Config.unique_sections[section_clazz.name])
    elif issubclass(section_clazz, Section):
        setattr(Config, attribute_name, Config.sections[section_clazz.name])
    else:
        raise TypeError

    if add_to_unconflicted_sections:
        Config._comparator._add_unconflicted_section(section_clazz.name)  # type: ignore[attr-defined]

    for exposed_configuration_method, configuration_method in configuration_methods:
        setattr(Config, exposed_configuration_method, configuration_method)


@_config_doc_for_method
def _inject_method(configuration_methods: List[tuple]):
    for exposed_configuration_method, configuration_method in configuration_methods:
        setattr(Config, exposed_configuration_method, configuration_method)