<commit_before>from __future__ import annotations

from typing import Any, Dict, ItemsView, KeysView, Mapping, Optional, Tuple, Union

DEFAULT = object()


class OptionsInterface:
    _hierarchy: Tuple[str, ...] = ()
    _legacy_fallback: Dict[str, Union[str, Tuple[str, ...]]] = {}
    _parent: Optional[OptionsInterface] = None

    def get(self, item: str, default: Any = DEFAULT) -> Any:
        if "." in item:
            item, attr = item.split(".", 1)
            try:
                return getattr(self, item).get(attr)
            except AttributeError:
                if default is not DEFAULT:
                    return default
                raise

        if default is not DEFAULT:
            try:
                return getattr(self, item, default)
            except AttributeError:
                return default

        return getattr(self, item)

    def __getitem__(self, item: str) -> Any:
        return self.get(item)

    def __setattr__(self, item: str, value: Any) -> None:
        if not hasattr(self, item) and item not in self.keys():
            exc = AttributeError(f"'{type(self).__name__}' object has no attribute '{item}'")
            exc.name = item
            exc.obj = self
            raise exc

        super().__setattr__(item, value)

    def __setitem__(self, item: str, value: Any) -> None:
        if "." in item:
            item, attr = item.split(".", 1)
            getattr(self, item)[attr] = value
            return

        if not hasattr(self, item):
            exc = AttributeError(f"'{type(self).__name__}' object has no attribute '{item}'")
            exc.name = item
            exc.obj = self
            raise exc

        setattr(self, item, value)

    def keys(self) -> KeysView:
        return self.__annotations__.keys()

    def items(self) -> ItemsView:
        return self.asdict().items()

    def asdict(self, *, prefix: str = "") -> Dict[str, Any]:
        result: Dict[str, Any] = {}<commit_msg>Fix for AttributeError values only usable in Python 3.10<commit_after>from __future__ import annotations

from typing import Any, Dict, ItemsView, KeysView, Mapping, Optional, Tuple, Union

DEFAULT = object()


class OptionsInterface:
    _hierarchy: Tuple[str, ...] = ()
    _legacy_fallback: Dict[str, Union[str, Tuple[str, ...]]] = {}
    _parent: Optional[OptionsInterface] = None

    def get(self, item: str, default: Any = DEFAULT) -> Any:
        if "." in item:
            item, attr = item.split(".", 1)
            try:
                return getattr(self, item).get(attr)
            except AttributeError:
                if default is not DEFAULT:
                    return default
                raise

        if default is not DEFAULT:
            try:
                return getattr(self, item, default)
            except AttributeError:
                return default

        return getattr(self, item)

    def __getitem__(self, item: str) -> Any:
        return self.get(item)

    def __setattr__(self, item: str, value: Any) -> None:
        if not hasattr(self, item) and item not in self.keys():
            exc = AttributeError(f"'{type(self).__name__}' object has no attribute '{item}'")
            if hasattr(exc, "name") and hasattr(exc, "obj"):
                exc.name = item
                exc.obj = self
            raise exc

        super().__setattr__(item, value)

    def __setitem__(self, item: str, value: Any) -> None:
        if "." in item:
            item, attr = item.split(".", 1)
            getattr(self, item)[attr] = value
            return

        if not hasattr(self, item):
            exc = AttributeError(f"'{type(self).__name__}' object has no attribute '{item}'")
            if hasattr(exc, "name") and hasattr(exc, "obj"):
                exc.name = item
                exc.obj = self
            raise exc

        setattr(self, item, value)

    def keys(self) -> KeysView:
        return self.__annotations__.keys()

    def items(self) -> ItemsView:
        return self.asdict().items()

    def asdict(self, *, prefix: str = "") -> Dict[str, Any]:
        result: Dict[str, Any] = {}
{'fraction_non_alphanumeric': 0.11970979443772672, 'fraction_numerical': 0.0016928657799274486, 'mean_word_length': 1.92090395480226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '947200', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1149, 'n_words': 358}