예제 #1
0
파일: utils.py 프로젝트: lamberta/tf-docs
    def _make_constructor_info(
            self, class_page_info: parser.ClassPageInfo) -> parser.PageInfo:
        """Convert a class description into a description of the constructor."""
        methods = pretty_docs.split_methods(class_page_info.methods)

        constructor_info = parser.PageInfo(full_name=class_page_info.full_name,
                                           py_object=class_page_info.py_object)

        # Replace the class py_object with constructors py_object. This is done
        # because each method is linted separately and class py_object contains the
        # source code of all its methods too.
        if methods.constructor is not None:
            constructor_info.py_object = methods.constructor.py_object
        else:
            constructor_info.py_object = None

        # Merge the constructor and class docstrings.
        class_blocks = pretty_docs.merge_blocks(class_page_info,
                                                methods.constructor)
        # Add the `Attributes` sections (if it exists) to the merged class blocks.
        if class_page_info.attr_block is not None:
            class_blocks.append(class_page_info.attr_block)

        new_doc = class_page_info.doc._replace(docstring_parts=class_blocks)

        constructor_info.set_doc(new_doc)

        return constructor_info
예제 #2
0
파일: utils.py 프로젝트: isabella232/docs-6
    def _fill_class_metric(self,
                           class_page_info: parser.ClassPageInfo) -> None:
        """Fills in the lint metrics for a class and its methods.

    The constructor and class's docstring is merged for linting. Class's
    `py_object` is replaced with that class's constructor's `py_object`.

    Every other method except `__init__` or `__new__` is linted separately.

    Args:
      class_page_info: A `ClassPageInfo` object containing information that's
        used to calculate metrics for the class and its methods.
    """

        methods: pretty_docs.Methods = pretty_docs.split_methods(
            class_page_info.methods)
        # Merge the constructor and class docstrings.
        class_blocks = pretty_docs.merge_blocks(class_page_info,
                                                methods.constructor)
        # Add the `Attributes` sections (if it exists) to the merged class blocks.
        if class_page_info.attr_block is not None:
            class_blocks.append(class_page_info.attr_block)
        # Replace the class py_object with constructors py_object. This is done
        # because each method is linted separately and class py_object contains the
        # source code of all its methods too.
        if methods.constructor is not None:
            class_page_info.py_object = methods.constructor.py_object
        else:
            class_page_info.py_object = None
        class_page_info.doc._replace(docstring_parts=class_blocks)

        package_group = self._find_pkg_group(class_page_info.full_name)

        self._lint(
            name=class_page_info.full_name,
            object_type=api_report_pb2.ObjectType.CLASS,
            package_group=package_group,
            page_info=class_page_info,
        )

        # Lint each method separately and add its metrics to the proto object.
        for method in methods.info_dict.values():
            # Skip the dunder methods from being in the report.
            if method.short_name not in public_api.ALLOWED_DUNDER_METHODS:
                self._lint(
                    name=method.full_name,
                    object_type=api_report_pb2.ObjectType.METHOD,
                    # Since methods are part of a class, each method belongs to the
                    # package group of the respective class.
                    package_group=package_group,
                    page_info=method,
                )
예제 #3
0
파일: utils.py 프로젝트: lamberta/tf-docs
    def _fill_class_metric(self,
                           class_page_info: parser.ClassPageInfo) -> None:
        """Fills in the lint metrics for a class and its methods.

    The constructor and class's docstring is merged for linting. Class's
    `py_object` is replaced with that class's constructor's `py_object`.

    Every other method except `__init__` or `__new__` is linted separately.

    Args:
      class_page_info: A `ClassPageInfo` object containing information that's
        used to calculate metrics for the class and its methods.
    """
        constructor_info = self._make_constructor_info(class_page_info)
        package_group = self._find_pkg_group(class_page_info.full_name)

        self._lint(
            name=class_page_info.full_name,
            object_type=api_report_pb2.ObjectType.CLASS,
            package_group=package_group,
            page_info=constructor_info,
        )

        methods: pretty_docs.Methods = pretty_docs.split_methods(
            class_page_info.methods)
        # Lint each method separately and add its metrics to the proto object.
        for method in methods.info_dict.values():
            # Skip the dunder methods from being in the report.
            if method.short_name not in public_api.ALLOWED_DUNDER_METHODS:
                self._lint(
                    name=method.full_name,
                    object_type=api_report_pb2.ObjectType.METHOD,
                    # Since methods are part of a class, each method belongs to the
                    # package group of the respective class.
                    package_group=package_group,
                    page_info=method,
                )