<commit_before>"""Helpers for class definitions."""

__all__ = [
    'LazyAttrs',
    'NondataProperty',
    'memorize',
    'nondata_property',
]

import functools

from garage import asserts


class LazyAttrs:
    """Compute (and store) attributes lazily."""

    def __init__(self, compute_attrs):
        self.__compute_attrs = compute_attrs
        self.__attrs = {}

    def __getattr__(self, name):
        if name not in self.__attrs:
            self.__compute_attrs(name, self.__attrs)
        return self.__attrs[name]


class NondataProperty:
    """A non-data descriptor version of property.

       This is "non-data" means that instances may override it.
    """

    def __init__(self, fget=None, doc=None):
        self.fget = fget
        if doc is None and fget is not None:
            doc = fget.__doc__
        self.__doc__ = doc

    def __get__(self, instance, _=None):
        if instance is None:
            return self
        if self.fget is None:
            raise AttributeError('unreadable attribute')
        return self.fget(instance)

    def getter(self, fget):
        return type(self)(fget, self.__doc__)
<commit_msg>Use __dict__ in LazyAttrs<commit_after>"""Helpers for class definitions."""

__all__ = [
    'LazyAttrs',
    'NondataProperty',
    'memorize',
    'nondata_property',
]

import functools

from garage import asserts


class LazyAttrs:
    """Compute (and store) attributes lazily."""

    def __init__(self, compute_attrs):
        self.__compute_attrs = compute_attrs

    def __getattr__(self, name):
        self.__compute_attrs(name, self.__dict__)
        return self.__dict__[name]


class NondataProperty:
    """A non-data descriptor version of property.

       This is "non-data" means that instances may override it.
    """

    def __init__(self, fget=None, doc=None):
        self.fget = fget
        if doc is None and fget is not None:
            doc = fget.__doc__
        self.__doc__ = doc

    def __get__(self, instance, _=None):
        if instance is None:
            return self
        if self.fget is None:
            raise AttributeError('unreadable attribute')
        return self.fget(instance)

    def getter(self, fget):
        return type(self)(fget, self.__doc__)

{'fraction_non_alphanumeric': 0.09650287737937141, 'fraction_numerical': 0.0, 'mean_word_length': 2.53125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5257597', 'n_tokens_mistral': 683, 'n_tokens_neox': 670, 'n_words': 199}