Implement `__doc__` to except signature · Issue #2907 · RustPython/RustPython · GitHub
Skip to content

Implement __doc__ to except signature #2907

Description

@moreal

This is nice! It does introduce an issue though, __doc__ now contains that text signature in its contents, you'll need to tweak doc to ignore the signature at the start (similar to CPythons _PyType_DocWithoutSignature).

Originally posted by @DimitrisJim in #2904 (comment)

Overview

Documentations of methods, types in CPython can have format like below:

<SIGNATURE>
--

<DOCUMENT>

And CPython's __doc__ property strips the signature through _PyType_DocWithoutSignature. Then, when you call <?>.__doc__, you will see only <DOCUMENT>. But RustPython hasn't implemented it so it should be implemented.

Example

Let's see the case of object type.

The full doc is:

PyDoc_STRVAR(object_doc,
"object()\n--\n\n"
"The base class of the class hierarchy.\n\n"
"When called, it accepts no arguments and returns a new featureless\n"
"instance that has no instance attributes and cannot be given any.\n");

As human-familiar:

object()
--

The base class of the class hierarchy.

When called, it accepts no arguments and returns a new featureless
Instance that has no instance attributes and cannot be given any.

And when call print(object.__doc__) in CPython 3.8.0, you will see:

The base class of the class hierarchy.

When called, it accepts no arguments and returns a new featureless
instance that has no instance attributes and cannot be given any.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    z-ca-2021Tag to track contrubution-academy 2021

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions