Skip to content

The deprecated decorator does not preserve class signatures in Sphinx via autodoc #86

@davidorme

Description

@davidorme

If I decorate a test function using the sphinx decorator:

from deprecated.sphinx import deprecated

@deprecated(reason="Because", version="1.0.0")
class Test2:
    """A docstring for a class."""

    def __init__(self, a: int = 1) -> None:
        self.a = a
        """An attribute"""

    def method(self) -> None:
        """A method."""

        pass

class Test3:
    """A docstring for a class."""

    def __init__(self, a: int = 1) -> None:
        self.a = a
        """An attribute"""

    def method(self) -> None:
        """A method."""

        pass

And then use autodoc to build the documentation, then it all looks good (methods, attributes etc show nicely), except that the class signature is generalised, compared to the actual signature of the undecorated test class

classTest2(*args, **kwargs)

    A docstring for a class.

    Deprecated since version 1.0.0: Because

Versus

classTest3(a: int = 1)
    A docstring for a class.

Is there a way to preserve those signature details?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions