Skip to content

Commit

Permalink
Fixed displaying "self" in class signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
AWhetter committed Jun 26, 2021
1 parent 5faec73 commit 08e61b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
7 changes: 4 additions & 3 deletions autoapi/mappers/python/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,10 @@ def create_class(self, data, options=None, **kwargs):
yield obj

def _record_typehints(self, obj):
if isinstance(
obj, (PythonClass, PythonFunction, PythonMethod)
) and not obj.overloads:
if (
isinstance(obj, (PythonClass, PythonFunction, PythonMethod))
and not obj.overloads
):
obj_annotations = {}

include_return_annotation = True
Expand Down
25 changes: 16 additions & 9 deletions autoapi/mappers/python/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
LOGGER = sphinx.util.logging.getLogger(__name__)


def _format_args(args_info, include_annotations=True):
def _format_args(args_info, include_annotations=True, ignore_self=None):
result = []

for prefix, name, annotation, default in args_info:
for i, (prefix, name, annotation, default) in enumerate(args_info):
if i == 0 and name == ignore_self:
continue
formatted = "{}{}{}{}".format(
prefix or "",
name or "",
Expand Down Expand Up @@ -351,14 +353,14 @@ def args(self):
args = ""

if self.constructor:
autodoc_typehints = getattr(self.app.config, "autodoc_typehints", "signature")
autodoc_typehints = getattr(
self.app.config, "autodoc_typehints", "signature"
)
show_annotations = autodoc_typehints != "none" and not (
autodoc_typehints == "description" and not self.constructor.overloads
)
args_data = self.constructor.obj["args"]
if args_data and args_data[0][1] == "self":
args_data = args_data[1:]
args = _format_args(args_data, show_annotations)
args = _format_args(args_data, show_annotations, ignore_self="self")

return args

Expand All @@ -368,10 +370,15 @@ def overloads(self):

if self.constructor:
overload_data = self.constructor.obj["overloads"]
if overload_data and overload_data[0][1] == "self":
overload_data = overload_data[1:]
autodoc_typehints = getattr(
self.app.config, "autodoc_typehints", "signature"
)
show_annotations = autodoc_typehints not in ("none", "description")
overloads = [
(_format_args(args), return_annotation)
(
_format_args(args, show_annotations, ignore_self="self"),
return_annotation,
)
for args, return_annotation in overload_data
]

Expand Down
6 changes: 5 additions & 1 deletion tests/python/test_pyintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def build(test_dir, confoverrides=None, **kwargs):
class TestSimpleModule:
@pytest.fixture(autouse=True, scope="class")
def built(self, builder):
builder("pyexample", warningiserror=True, confoverrides={"suppress_warnings": ["app"]})
builder(
"pyexample",
warningiserror=True,
confoverrides={"suppress_warnings": ["app"]},
)

def test_integration(self):
self.check_integration("_build/text/autoapi/example/index.txt")
Expand Down

0 comments on commit 08e61b9

Please sign in to comment.