Skip to content

Implement __doc__ to except signature #2907

Closed

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

  1. youknowone commented on Aug 18, 2021

    @youknowone
    Member

    If this is only adopt to internal doc, we can try to do it better in our derive macros like parsing it from compile time and saving separated variables for __text_signature__ and __doc__

  2. youknowone commented on Jul 6, 2022

    @youknowone
    Member

    now we do this by macro

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