pdoc icon indicating copy to clipboard operation
pdoc copied to clipboard

classmethods documented as a static method

Open dmot7291 opened this issue 6 years ago • 3 comments

Expected Behavior

image

Actual Behavior

image

Steps to Reproduce

Example code:

import documentation_test.submod1.submod1 as submod1
import documentation_test.submod2.submod2 as submod2

__all__ = ['testFunction', 'testClass']


class testClass(object):

    """Summary of class

    Attributes
    ----------
    arg : str
        a string to print
    """

    def __init__(self, arg: str):
        """Summary of init

        Parameters
        ----------
        arg : str, optional
            a string to print
        """
        super(testClass, self).__init__()
        self.arg = arg

    @classmethod
    def createString(cls, aString: str):
        """create a string

        Parameters
        ----------
        aString : str
            a string to print
        """
        return cls(arg=aString)

    def printString(self):
        """Print a string
        """
        print(self.arg)


def testFunction(anything: str = 'test') -> None:
    """test function for a demo import of whole module

    Parameters
    ----------
    anything : str, optional
        a test string

    Returns
    -------
    None
    """
    print(anything)


submod1.submod1('string from submod1 in base')

submod2.submod2('string from submod2 in base')

Command ran: pdoc --config show_type_annotations=True --html src/documentation_test --force

Additional info

  • pdoc version: 0.7.2
  • python 3.8

Not sure if this is intentional or I have done something nonstandard. No matter what I try; class in a submodule, class with both static and class methods, etc. I get the same result.

dmot7291 avatar Nov 18 '19 22:11 dmot7291

In a way it's intentional. pdoc.Function has historically only known functions and methods. https://github.com/pdoc3/pdoc/blob/3a5e1d1241562691cb64584add3c8ed647ea2505/pdoc/init.py#L1028-L1033 The unbound functions are simplified into "Static methods" because they behave like so. I guess calling them "Functions" could be just as good.

kernc avatar Nov 19 '19 02:11 kernc

I'm more confused that is it intentional, as a static method can’t access or modify class state - labeling a class method this way seems unintuative.

dtomlinson91 avatar Nov 19 '19 10:11 dtomlinson91

Agreed. If you'd like to propose a patch to fix this, it should be reviewed favorably.

kernc avatar Nov 19 '19 16:11 kernc