0

I have a Python class with methods that include docstrings. When I hover over the method names in my IDE (I'm using PyCharm), the docstring content appears twice. Here's an example of one of my methods:

import numpy as np

class ReLu:
    """
    ReLu (Rectified Linear Unit) activation function for neural networks.
    """

    def forward_train(self, z: np.array) -> np.array:
                """
    Perform the forward pass during training and store the input for use in backpropagation.

    Args:
        z (np.array): The input data to the activation function.

    Returns:
        np.array: The result of applying the ReLU function to the input data.
    """
        self.__z = z
        return self.forward(z)

Problem: When I hover over the forward_train method in PyCharm, I see the text twice, like this:

    Perform the forward pass during training and store the input for use in backpropagation.  
Args: z (np. array): The input data to the activation function.  Returns: np. array: The result of applying the ReLU function to the input data.
    Params:
    z – The input data to the activation function.
    Returns:
    The result of applying the ReLU function to the input data.

It looks like the IDE is displaying my docstring twice, formatted differently. I want to know how to avoid this duplication or what might be causing it.

4
  • That's not the conventional layout for a docstring, which may be confusing things: peps.python.org/pep-0257
    – jonrsharpe
    Commented Sep 5 at 15:13
  • 1
    It's not showing the whole docstring twice. It's extracting the parameter and return information from the docstring and showing those details in addition to the docstring.
    – Barmar
    Commented Sep 5 at 15:23
  • @Barmar that may be. But is there a possibility to show it only once in PyCharm.
    – dracule22
    Commented Sep 5 at 16:41
  • I don't have PyCharm, but I have PhpStorm. There's a preferences checkbox for "Show quick documentation on hover", but nothing to customize the format of the quick documentation as far as I can tell.
    – Barmar
    Commented Sep 5 at 16:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.