def add_directive_header(self, sig):
        """ Add the directive header 'attribute' with the annotation
        option set to the trait definition.

        """
        ClassLevelDocumenter.add_directive_header(self, sig)
        try:
            definition = trait_definition(
                cls=self.parent,
                trait_name=self.object_name,
            )
        except ValueError:
            # Without this, a failure to find the trait definition aborts
            # the whole documentation build.
            logger.warning(
                "No definition for the trait {!r} could be found in "
                "class {!r}.".format(self.object_name, self.parent),
                exc_info=True)
            return

        # Workaround for enthought/traits#493: if the definition is multiline,
        # throw away all lines after the first.
        if "\n" in definition:
            definition = definition.partition("\n")[0] + " …"

        self.add_line("   :annotation: = {0}".format(definition), "<autodoc>")
Beispiel #2
0
def i_add_directive_header(self, sig):
    ClassLevelDocumenter.add_directive_header(self, sig)
    source_name = self.get_sourcename()
    if not self.options.annotation:
        if not self._datadescriptor:
            # obtain annotation for this attribute
            annotations = getattr(self.parent, '__annotations__', {})
            if annotations and self.objpath[-1] in annotations:
                objrepr = stringify_type_hint(annotations.get(
                    self.objpath[-1]))
                self.add_line('   :type: ' + objrepr, source_name)
            else:
                key = ('.'.join(self.objpath[:-1]), self.objpath[-1])
                if self.analyzer and key in self.analyzer.annotations:
                    v = self.analyzer.annotations[key]
                    if v == "_np.ndarray":
                        v = "ndarray"
                    elif v == "_typing.Sequence[str]":
                        v = "list of str"
                    else:
                        v = v.replace("_typing.", "")
                        v = v.replace("_np.", "")
                    self.add_line(f"   :type: {v}", source_name)

            # ## Remove (= None).
            # try:
            #     obj_repr = object_description(self.object)
            #     self.add_line('   :value: ' + obj_repr, source_name)
            # except ValueError:
            #     pass
    elif self.options.annotation is SUPPRESS:
        pass
    else:
        self.add_line('   :annotation: %s' % self.options.annotation,
                      source_name)
Beispiel #3
0
 def add_directive_header(self, sig):
     # We can't call super() here, because we want to *skip* executing
     # FunctionDocumenter.add_directive_header, because starting in Sphinx
     # 2.1 it does its own sniffing, which is worse than ours and will
     # break ours. So we jump straight to the superclass.
     ClassLevelDocumenter.add_directive_header(self, sig)
     passthrough_option_lines(self, extended_method_option_spec)
    def add_directive_header(self, sig):
        """ Add the directive header 'attribute' with the annotation
        option set to the trait definition.

        """
        ClassLevelDocumenter.add_directive_header(self, sig)
        definition = self._get_trait_definition()
        self.add_line('   :annotation: = {0}'.format(definition), '<autodoc>')
Beispiel #5
0
    def add_directive_header(self, sig):
        """ Add the directive header 'attribute' with the annotation
        option set to the trait definition.

        """
        ClassLevelDocumenter.add_directive_header(self, sig)
        definition = self._get_trait_definition()
        self.add_line(u'   :annotation: = {0}'.format(definition), '<autodoc>')
    def add_directive_header(self, sig: str):
        """
		Add the directive's header.

		:param sig:
		"""

        sourcename = self.get_sourcename()

        no_value = self.options.get("no-value", False)
        no_type = self.options.get("no-type", False)

        if not self.options.get("annotation", ''):
            ClassLevelDocumenter.add_directive_header(self, sig)

            # data descriptors do not have useful values
            if not no_value and not self._datadescriptor:
                if "value" in self.options:
                    self.add_line("   :value: " + self.options["value"],
                                  sourcename)
                else:
                    with suppress(ValueError):
                        if self.object is not INSTANCEATTR:
                            objrepr = object_description(self.object)
                            self.add_line("   :value: " + objrepr, sourcename)

            self.add_line('', sourcename)

            if not no_type:
                if "type" in self.options:
                    self.add_line(type_template % self.options["type"],
                                  sourcename)
                else:
                    # obtain type annotation for this attribute
                    the_type = get_variable_type(self)
                    if not the_type.strip():
                        obj_type = type(self.object)

                        if obj_type is object:
                            return

                        try:
                            the_type = format_annotation(obj_type)
                        except Exception:
                            return

                    line = type_template % the_type
                    self.add_line(line, sourcename)

        else:
            super().add_directive_header(sig)
    def add_directive_header(self, sig):
        """ Add the directive header 'attribute' with the annotation
        option set to the trait definition.

        """
        ClassLevelDocumenter.add_directive_header(self, sig)
        definition = self._get_trait_definition()

        # Workaround for enthought/traits#493: if the definition is multiline,
        # throw away all lines after the first.
        if "\n" in definition:
            definition = definition.partition("\n")[0] + " …"

        self.add_line("   :annotation: = {0}".format(definition), "<autodoc>")
    def add_directive_header(self, sig):
        """ Add the sphinx directives.

        Add the 'attribute' directive with the annotation option
        set to the traitlet type

        """
        ClassLevelDocumenter.add_directive_header(self, sig)
        if hasattr(self, 'get_sourcename'):
            sourcename = self.get_sourcename()
        else:
            sourcename = u'<autodoc>'

        trait_type = type(self.object).__name__
        self.add_line('   :annotation: = {0}'.format(trait_type), sourcename)
Beispiel #9
0
 def add_directive_header(self, sig: str) -> None:
     ClassLevelDocumenter.add_directive_header(self, sig)
     sourcename = self.get_sourcename()
     if not self.options.annotation:
         if not self._datadescriptor:
             try:
                 objrepr = str(int(self.object))
             except ValueError:
                 pass
             else:
                 self.add_line('   :annotation: = ' + objrepr, sourcename)
     elif self.options.annotation is SUPPRESS:
         pass
     else:
         self.add_line('   :annotation: %s' % self.options.annotation,
                       sourcename)
Beispiel #10
0
 def add_directive_header(self, sig):
     ClassLevelDocumenter.add_directive_header(self, sig)
     if not self.options.annotation:
         if not self._datadescriptor:
             try:
                 objrepr = safe_repr(self.object)
             except ValueError:
                 pass
             else:
                 if not SKIP_ANNOTATION_RE.match(self.fullname):
                     self.add_line(u'   :annotation: = ' + objrepr,
                                   '<autodoc>')
     elif self.options.annotation is SUPPRESS:
         pass
     else:
         self.add_line(u'   :annotation: %s' % self.options.annotation,
                       '<autodoc>')
    def add_directive_header(self, sig):
        """ Add the sphinx directives.

        Add the 'attribute' directive with the annotation option
        set to the trait definition.

        """
        ClassLevelDocumenter.add_directive_header(self, sig)
        if hasattr(self, 'get_sourcename'):
            sourcename = self.get_sourcename()
        else:
            sourcename = u'<autodoc>'
        try:
            definition = get_trait_definition(self.parent, self.object_name)
        except DefinitionError as error:
            self.directive.warn(error.args[0])
        else:
            self.add_line(
                '   :annotation: = {0}'.format(definition), sourcename)
Beispiel #12
0
def iad_add_directive_header(self, sig):
    ClassLevelDocumenter.add_directive_header(self, sig)
Beispiel #13
0
def add_directive_header(self, sig):
    ClassLevelDocumenter.add_directive_header(self, sig)