<commit_before># -*- coding: utf-8 -*-
#
# Copyright © 2015,2016 <NAME> <<EMAIL>>
# Copyright © 2015,2016 Collabora Ltd
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library.  If not, see <http://www.gnu.org/licenses/>.

"""
Defines the base symbols recognized by hotdoc.

Code-parsing extensions should only create symbols defined
here for the while, subclassing will be formalized in the
future.
"""

from hotdoc.core.comment import comment_from_tag
from hotdoc.core.links import Link


# pylint: disable=too-many-instance-attributes
class Symbol:
    """
    The base class for all symbols, there should be no reason for
    instantiating it directly.
    """
    __tablename__ = 'symbols'
    standalone = True

    def __init__(self):
        self.extension_contents = {}
        self.extension_attributes = {}
        self.skip = False

        self.extra = {}
        self.comment = None
        self.unique_name = None
        self.display_name = None
        self.filename = None
        self.lineno = -1
        self.extent_start = -1
        self.extent_end = -1
        self.link = None
        self.project_name = None
        self.parent_name = None
        self.aliases = []

    def __repr__(self):
        return "%s(unique_name=%s, filename=%s, project=%s)" % (
            type(self).__name__, self.unique_name, self.filename,
            self.project_name)

    @classmethod
    def get_plural_name(cls):
        """Default implementation of the vmethod
        to retrieve Plurial form of the symbol name."""
        return cls.__tablename__.replace("_", " ").title()

    # FIXME: this is a bit awkward to use.
    def add_extension_attribute(self, ext_name, key, value):
        """
        Banana banana
        """
        attributes = self.extension_attributes.pop(ext_name, {})
        attributes[key] = value
        self.extension_attributes[ext_name] = attributes

    def get_extension_attribute(self, ext_name, key):
        """
        Banana banana
        """
        attributes = self.extension_attributes.get(ext_name)
        if not attributes:
            return None
        return attributes.get(key)

    # pylint: disable=no-self-use
    def get_children_symbols(self):
        """
        Banana banana
        """
        return self.aliases

    # pylint: disable=unidiomatic-typecheck
    # pylint: disable=no-member
    def update_children_comments(self):
        """
        Banana banana
        """
        if self.comment is None:
            return

        for sym in self.get_children_symbols():
            if isinstance(sym, ParameterSymbol):
                sym.comment = self.comment.params.get(sym.argname)
            elif isinstance(sym, FieldSymbol):
                param_comment = self.comment.params.get(sym.member_name)
                if param_comment and (not sym.comment or not sym.comment.description):
                    sym.comment = param_comment
            elif isinstance(sym, EnumMemberSymbol):
                if not sym.comment or not sym.comment.description:
                    sym.comment = self.comment.params.get(sym.unique_name)
            elif isinstance(sym, ReturnItemSymbol):
                tag = self.comment.tags.get('returns')
                sym.comment = comment_from_tag(tag)
            elif type(sym) == Symbol:
                sym.comment = self.comment.params.get(sym.display_name)<commit_msg>symbols: do not list aliases as children<commit_after># -*- coding: utf-8 -*-
#
# Copyright © 2015,2016 <NAME> <<EMAIL>.<EMAIL>>
# Copyright © 2015,2016 Collabora Ltd
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library.  If not, see <http://www.gnu.org/licenses/>.

"""
Defines the base symbols recognized by hotdoc.

Code-parsing extensions should only create symbols defined
here for the while, subclassing will be formalized in the
future.
"""

from hotdoc.core.comment import comment_from_tag
from hotdoc.core.links import Link


# pylint: disable=too-many-instance-attributes
class Symbol:
    """
    The base class for all symbols, there should be no reason for
    instantiating it directly.
    """
    __tablename__ = 'symbols'
    standalone = True

    def __init__(self):
        self.extension_contents = {}
        self.extension_attributes = {}
        self.skip = False

        self.extra = {}
        self.comment = None
        self.unique_name = None
        self.display_name = None
        self.filename = None
        self.lineno = -1
        self.extent_start = -1
        self.extent_end = -1
        self.link = None
        self.project_name = None
        self.parent_name = None
        self.aliases = []

    def __repr__(self):
        return "%s(unique_name=%s, filename=%s, project=%s)" % (
            type(self).__name__, self.unique_name, self.filename,
            self.project_name)

    @classmethod
    def get_plural_name(cls):
        """Default implementation of the vmethod
        to retrieve Plurial form of the symbol name."""
        return cls.__tablename__.replace("_", " ").title()

    # FIXME: this is a bit awkward to use.
    def add_extension_attribute(self, ext_name, key, value):
        """
        Banana banana
        """
        attributes = self.extension_attributes.pop(ext_name, {})
        attributes[key] = value
        self.extension_attributes[ext_name] = attributes

    def get_extension_attribute(self, ext_name, key):
        """
        Banana banana
        """
        attributes = self.extension_attributes.get(ext_name)
        if not attributes:
            return None
        return attributes.get(key)

    # pylint: disable=no-self-use
    def get_children_symbols(self):
        """
        Banana banana
        """
        return []

    # pylint: disable=unidiomatic-typecheck
    # pylint: disable=no-member
    def update_children_comments(self):
        """
        Banana banana
        """
        if self.comment is None:
            return

        for sym in self.get_children_symbols():
            if isinstance(sym, ParameterSymbol):
                sym.comment = self.comment.params.get(sym.argname)
            elif isinstance(sym, FieldSymbol):
                param_comment = self.comment.params.get(sym.member_name)
                if param_comment and (not sym.comment or not sym.comment.description):
                    sym.comment = param_comment
            elif isinstance(sym, EnumMemberSymbol):
                if not sym.comment or not sym.comment.description:
                    sym.comment = self.comment.params.get(sym.unique_name)
            elif isinstance(sym, ReturnItemSymbol):
                tag = self.comment.tags.get('returns')
                sym.comment = comment_from_tag(tag)
            elif type(sym) == Symbol:
                sym.comment = self.comment.params.get(sym.display_name)
{'fraction_non_alphanumeric': 0.08985507246376812, 'fraction_numerical': 0.005545053560176433, 'mean_word_length': 2.3813378781423093, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6163368', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2111, 'n_words': 668}