<commit_before>import ast


class ModuleReflection:
    @classmethod
    def from_file(cls, file):
        with open(file, 'r') as handle:
            content = handle.read()

        return cls.from_string(file, content)

    @classmethod
    def from_string(cls, name, content):
        return cls(name, ast.parse(content))

    def __init__(self, name, node):
        self.__name = name
        self.__node = node

    def __repr__(self):
        return self.__name

    def classes(self):
        return [
            ClassReflection(node)
            for node in ast.walk(self.__node)
            if isinstance(node, ast.ClassDef)
        ]


class ClassReflection:
    def __init__(self, node):
        self.__node = node

    def __repr__(self):
        return self.__node.name

    def method(self, name):
        nodes = [
            node
            for node in self.__node.body
            if isinstance(node, ast.FunctionDef) and node.name == name
        ]

        return MethodReflection(nodes[0])

    def methods(self):
        return [
            MethodReflection(node)
            for node in self.__node.body
            if isinstance(node, ast.FunctionDef)
        ]

    def vars(self):
        return list(self.__class_vars() | self.__instance_vars())

    def __class_vars(self):
        return {
            target.id
            for node in self.__node.body
            if isinstance(node, ast.Assign)
            for target in node.targets
        }

    def __instance_vars(self):
        return {
            node.attr
            for node in ast.walk(self.__node)
            if isinstance(node, ast.Attribute) and node.value.id == 'self'
        }


class MethodReflection:
    def __init__(self, node):
        self.__node = node

    def __repr__(self):
        return self.__node.name

    def is_constructor(self):
        return self.__node.name == '__init__'

    def calls(self):
        return list(self.__calls())

    def vars(self):
        return list(self.__vars() - self.__calls())

    def __vars(self):
        return {
            node.attr
            for node in ast.walk(self.__node)
            if isinstance(node, ast.Attribute)
               and node.value.id in ('cls', 'self')
        }

    def __calls(self):
        return {
            node.func.attr
            for node in ast.walk(self.__node)
            if isinstance(node, ast.Call)
               and isinstance(node.func, ast.Attribute)
               and node.func.value.id in ('cls', 'self')
        }

    def __call_name(self, node):
        if isinstance(node.func, ast.Attribute):
            return node.func.value.id
        return node.func.id<commit_msg>adjust indent to match pep8<commit_after>import ast


class ModuleReflection:
    @classmethod
    def from_file(cls, file):
        with open(file, 'r') as handle:
            content = handle.read()

        return cls.from_string(file, content)

    @classmethod
    def from_string(cls, name, content):
        return cls(name, ast.parse(content))

    def __init__(self, name, node):
        self.__name = name
        self.__node = node

    def __repr__(self):
        return self.__name

    def classes(self):
        return [
            ClassReflection(node)
            for node in ast.walk(self.__node)
            if isinstance(node, ast.ClassDef)
        ]


class ClassReflection:
    def __init__(self, node):
        self.__node = node

    def __repr__(self):
        return self.__node.name

    def method(self, name):
        nodes = [
            node
            for node in self.__node.body
            if isinstance(node, ast.FunctionDef) and node.name == name
        ]

        return MethodReflection(nodes[0])

    def methods(self):
        return [
            MethodReflection(node)
            for node in self.__node.body
            if isinstance(node, ast.FunctionDef)
        ]

    def vars(self):
        return list(self.__class_vars() | self.__instance_vars())

    def __class_vars(self):
        return {
            target.id
            for node in self.__node.body
            if isinstance(node, ast.Assign)
            for target in node.targets
        }

    def __instance_vars(self):
        return {
            node.attr
            for node in ast.walk(self.__node)
            if isinstance(node, ast.Attribute) and node.value.id == 'self'
        }


class MethodReflection:
    def __init__(self, node):
        self.__node = node

    def __repr__(self):
        return self.__node.name

    def is_constructor(self):
        return self.__node.name == '__init__'

    def calls(self):
        return list(self.__calls())

    def vars(self):
        return list(self.__vars() - self.__calls())

    def __vars(self):
        return {
            node.attr
            for node in ast.walk(self.__node)
            if isinstance(node, ast.Attribute)
            and node.value.id in ('cls', 'self')
        }

    def __calls(self):
        return {
            node.func.attr
            for node in ast.walk(self.__node)
            if isinstance(node, ast.Call)
            and isinstance(node.func, ast.Attribute)
            and node.func.value.id in ('cls', 'self')
        }

    def __call_name(self, node):
        if isinstance(node.func, ast.Attribute):
            return node.func.value.id
        return node.func.id
{'fraction_non_alphanumeric': 0.09748837209302326, 'fraction_numerical': 0.0005581395348837209, 'mean_word_length': 1.7654320987654322, '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': '6111137', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1486, 'n_words': 387}