<commit_before>from sphinx.ext import autodoc

from .mappers.python import (
    PythonFunction,
    PythonClass,
    PythonMethod,
    PythonData,
    PythonAttribute,
    PythonException,
)
from . import utils


class AutoapiDocumenter(autodoc.Documenter):
    def get_attr(self, obj, name, *defargs):
        if (hasattr(self.env.app, 'registry')
                and hasattr(self.env.app.registry, 'autodocattrgettrs')):
            attrgetters = self.env.app.registry.autodoc_attrgettrs
        else:
            attrgetters = autodoc.AutoDirective._special_attrgetters

        for type_, func in attrgetters.items():
            if isinstance(obj, type_):
                return func(obj, name, *defargs)

        if name == '__doc__':
            return obj.docstring

        for child in obj.children:
            if child.name == name:
                return child

        if defargs:
            return defargs[0]

        raise AttributeError(name)

    def import_object(self):
        path_stack = list(reversed(self.fullname.split('.')))
        objects = self.env.autoapi_mapper.objects
        parent = objects[utils.slugify(path_stack.pop())]
        while parent and path_stack:
            parent = self.get_attr(parent, path_stack.pop(), None)

        if not parent:
            return False

        self.object = parent
        self.object_name = parent.name
        return True

    def get_real_modname(self):
        # Return a fake modname so that nothing can be imported
        return None

    def get_doc(self, encoding=None, ignore=1):
        return [self.object.docstring.splitlines()]

    def process_doc(self, docstrings):
        for docstring in docstrings:
            for line in docstring:
                yield line

        yield ''

    def get_object_members(self, want_all):
        children = ((child.name, child) for child in self.object.children)

        if not want_all:
            if not self.options.members:
                return False, []

            children = (
                child for child in children if child[0] in self.options.members
            )

        return False, sorted(children)<commit_msg>Fixed autodoc not documenting anything in submodules or subpackages<commit_after>from sphinx.ext import autodoc

from .mappers.python import (
    PythonFunction,
    PythonClass,
    PythonMethod,
    PythonData,
    PythonAttribute,
    PythonException,
)
from . import utils


class AutoapiDocumenter(autodoc.Documenter):
    def get_attr(self, obj, name, *defargs):
        if (hasattr(self.env.app, 'registry')
                and hasattr(self.env.app.registry, 'autodocattrgettrs')):
            attrgetters = self.env.app.registry.autodoc_attrgettrs
        else:
            attrgetters = autodoc.AutoDirective._special_attrgetters

        for type_, func in attrgetters.items():
            if isinstance(obj, type_):
                return func(obj, name, *defargs)

        if name == '__doc__':
            return obj.docstring

        for child in obj.children:
            if child.name == name:
                return child

        if defargs:
            return defargs[0]

        raise AttributeError(name)

    def import_object(self):
        max_splits = self.fullname.count('.')
        for num_splits in range(max_splits, 0, -1):
            path_stack = list(reversed(self.fullname.rsplit('.', num_splits)))
            objects = self.env.autoapi_mapper.objects
            parent = objects[path_stack.pop()]
            while parent and path_stack:
                parent = self.get_attr(parent, path_stack.pop(), None)

            if parent:
                self.object = parent
                self.object_name = parent.name
                return True

        return False

    def get_real_modname(self):
        # Return a fake modname so that nothing can be imported
        return None

    def get_doc(self, encoding=None, ignore=1):
        return [self.object.docstring.splitlines()]

    def process_doc(self, docstrings):
        for docstring in docstrings:
            for line in docstring:
                yield line

        yield ''

    def get_object_members(self, want_all):
        children = ((child.name, child) for child in self.object.children)

        if not want_all:
            if not self.options.members:
                return False, []

            children = (
                child for child in children if child[0] in self.options.members
            )

        return False, sorted(children)
{'fraction_non_alphanumeric': 0.08388520971302428, 'fraction_numerical': 0.0017660044150110375, 'mean_word_length': 2.014637391882901, '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': '882795', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1237, 'n_words': 331}